api-console icon indicating copy to clipboard operation
api-console copied to clipboard

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

Open denis-kalinin opened this issue 10 years ago • 1 comments

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 avatar Jun 10 '16 13:06 denis-kalinin

OK, has changed in getDocumentationContent:

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

Works!

denis-kalinin avatar Jun 10 '16 17:06 denis-kalinin