Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty documentation: getDocumentationContent splits text using \n - doesn't work if RAML contains Carrige Return, CR + LF #294

Closed
denis-kalinin opened this issue Jun 10, 2016 · 1 comment
Milestone

Comments

@denis-kalinin
Copy link

denis-kalinin commented Jun 10, 2016

The error is in the directive RAML.Directives.rootDocumentation in root-documentation.js
Consider the following code containing CR+LF (\r\n) at the end of lines:

#%RAML 0.8

---
title: Cool REST API
baseUri: http://example.com/api
version: v1
documentation:
  - title: Getting started
    content: |
      # Welcome to our cool API
      With our API you can cast magic!

If the string in content node is # Welcome to our cool API\r\n, i.e. formatted in Windows, then function getDocumentationContent() splitting content node to lines will get the first line as:

var lines = ["#Welcome to our cool API\r", "", "With our API you can cast magic!"];
// \r is invisible in debugger, and it seems strange why getting "identical" string in array with indexOf() fails

after splitting the content node in function getDocumentationContent(). At the same time the function getMarkdownHeaders() keeps the same string in headers as

// we get header from content as: var headers = content.match(/^#+\s(.*)$/gim);
var selected = "#Welcome to our cool API";
// there is no \r at the end.

then in getDocumentationContent we try to match these string with:

var index = lines.indexOf(selected);
//and we get index=-1 because of invisible \r at the end of lines[0]

I think this is the reason.

@denis-kalinin
Copy link
Author

OK, has changed in getDocumentationContent:

// var lines  = content.split("\n");
var lines  = content.split(/\r|\n/);

Works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants