将 Markdown/ASCI(多行)转换为 HTML(nodejs)
Converting Markdown/ASCI (Multiline) To HTML (nodejs)
我目前在我的编辑器中有这个..
* Line one
* Line two
some more info
数据库中的数据库是这样的
* Line one\r\n* Line two\r\nsome more info
我正在使用 Markdown 包将 markdown 转换为 HTML 以显示在我的网站上,这很好用。
但是它忽略了换行符,因此给了我这个输出...
<ul><li>Line one</li><li>Line two\r\nsome more info</li></ul>
当我想要的输出是...
<ul><li>Line one</li><li>Line two</li></ul>some more info
我想我需要在我 运行 通过降价之前从我的单行中制作一个 'multiline string' 吗?
对最佳方法有什么想法吗?
目前正在使用此代码
var markdown = require( "markdown" ).markdown;
var unMarkdownDescriptions = function(description){
//Check if currently contains HTML.
if(typeof description !== "undefined"){
if(description.indexOf("<") !=-1){
return description;
}else{
return html_content = markdown.toHTML(description);
}
}else{
return '';
}
}
当前代码检查是否已在数据库中存储为 HTML 并忽略它们(我们从 HTML 迁移到 MD,在 ERP 上生成的 HTML 充其量是狡猾的多次!)
However it is ignoring the line breaks
根据 Markdown spec:
这就是它的行为方式
A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line — a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be indented with spaces or tabs.
The implication of the "one or more consecutive lines of text" rule is that Markdown supports "hard-wrapped" text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type’s “Convert Line Breaks” option) which translate every line break character in a paragraph into a <br />
tag.
要获得所需的输出,只需在列表后添加一个空行:
* Line one
* Line two
some more info
我目前在我的编辑器中有这个..
* Line one
* Line two
some more info
数据库中的数据库是这样的
* Line one\r\n* Line two\r\nsome more info
我正在使用 Markdown 包将 markdown 转换为 HTML 以显示在我的网站上,这很好用。
但是它忽略了换行符,因此给了我这个输出...
<ul><li>Line one</li><li>Line two\r\nsome more info</li></ul>
当我想要的输出是...
<ul><li>Line one</li><li>Line two</li></ul>some more info
我想我需要在我 运行 通过降价之前从我的单行中制作一个 'multiline string' 吗?
对最佳方法有什么想法吗?
目前正在使用此代码
var markdown = require( "markdown" ).markdown;
var unMarkdownDescriptions = function(description){
//Check if currently contains HTML.
if(typeof description !== "undefined"){
if(description.indexOf("<") !=-1){
return description;
}else{
return html_content = markdown.toHTML(description);
}
}else{
return '';
}
}
当前代码检查是否已在数据库中存储为 HTML 并忽略它们(我们从 HTML 迁移到 MD,在 ERP 上生成的 HTML 充其量是狡猾的多次!)
However it is ignoring the line breaks
根据 Markdown spec:
这就是它的行为方式A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line — a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be indented with spaces or tabs.
The implication of the "one or more consecutive lines of text" rule is that Markdown supports "hard-wrapped" text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type’s “Convert Line Breaks” option) which translate every line break character in a paragraph into a
<br />
tag.
要获得所需的输出,只需在列表后添加一个空行:
* Line one
* Line two
some more info