summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-markdown
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-markdown')
-rw-r--r--packages/gitbook-markdown/lib/annotate_blocks.js2
-rw-r--r--packages/gitbook-markdown/lib/annotate_inline.js2
-rw-r--r--packages/gitbook-markdown/lib/page.js28
-rw-r--r--packages/gitbook-markdown/test/page.js4
4 files changed, 18 insertions, 18 deletions
diff --git a/packages/gitbook-markdown/lib/annotate_blocks.js b/packages/gitbook-markdown/lib/annotate_blocks.js
index 88653ad..cb8ada8 100644
--- a/packages/gitbook-markdown/lib/annotate_blocks.js
+++ b/packages/gitbook-markdown/lib/annotate_blocks.js
@@ -27,7 +27,7 @@ var rules = { newline: /^\n+/,
// List of all the regexes we want to run
var ruleTypes = [
-'newline', 'rawStart', 'rawEnd', 'code', 'fences', 'footnote', 'math', 'heading',
+'rawStart', 'rawEnd', 'newline', 'code', 'fences', 'footnote', 'math', 'heading',
'nptable', 'lheading', 'hr', 'blockquote', 'list',
'html', 'def', 'table', 'paragraph', 'text',
];
diff --git a/packages/gitbook-markdown/lib/annotate_inline.js b/packages/gitbook-markdown/lib/annotate_inline.js
index 649cec1..376b092 100644
--- a/packages/gitbook-markdown/lib/annotate_inline.js
+++ b/packages/gitbook-markdown/lib/annotate_inline.js
@@ -18,7 +18,7 @@ var rules = {
text: /^[\s\S]+?(?=[\\<!\[_*`$~]|https?:\/\/| {2,}\n|$)/,
math: /^\$\$\s*([\s\S]*?[^\$])\s*\$\$(?!\$)/,
rawStart: /^{%([\s]*)raw([\s]*)%}/,
- rawEnd: /^{%([\s]*)endraw([\s]*)%}/
+ rawEnd: /[\s\S]*{%([\s]*)endraw([\s]*)%}/ // /^{%([\s]*)endraw([\s]*)%}/
//_inside: /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/,
//_href: /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/
};
diff --git a/packages/gitbook-markdown/lib/page.js b/packages/gitbook-markdown/lib/page.js
index 9b0f37f..1cd55a8 100644
--- a/packages/gitbook-markdown/lib/page.js
+++ b/packages/gitbook-markdown/lib/page.js
@@ -15,8 +15,6 @@ function combine(nodes) {
return _.pluck(nodes, 'raw').join('');
}
-
-
function preparePage(src) {
var lexed = annotate.blocks(src);
var levelRaw = 0;
@@ -26,31 +24,29 @@ function preparePage(src) {
el.raw = escape(el.raw);
} else if (el.type == 'rawStart') {
levelRaw = levelRaw + 1;
- } else if (el.type == 'rawStart') {
- levelRaw = levelRaw - 1;
+ } else if (el.type == 'rawEnd') {
+ levelRaw = 0;
}
return el;
};
var escaped = lexed
- // Escape code blocks
- .map(escapeCodeElement)
-
- // Escape inline code blocks
.map(function(el) {
// Only escape paragraphs and headings
- if(!(el.type == 'paragraph' || el.type == 'heading')) {
- return el;
- }
+ if(el.type == 'paragraph' || el.type == 'heading') {
+ var line = annotate.inline(el.raw);
- // Escape inline code blocks
- var newInline = annotate.inline(el.raw).map(escapeCodeElement);
+ // Escape inline code blocks
+ line = line.map(escapeCodeElement);
- // Change raw source code
- el.raw = combine(newInline);
+ // Change raw source code
+ el.raw = combine(line);
- return el;
+ return el;
+ } else {
+ return escapeCodeElement(el);
+ }
});
return combine(escaped);
diff --git a/packages/gitbook-markdown/test/page.js b/packages/gitbook-markdown/test/page.js
index 6ed6d96..c7384b6 100644
--- a/packages/gitbook-markdown/test/page.js
+++ b/packages/gitbook-markdown/test/page.js
@@ -51,6 +51,10 @@ describe('Page parsing', function() {
page.prepare('{% raw %}Hello {{ "Bonjour" }} ```test```{% endraw %}'),
'{% raw %}Hello {{ "Bonjour" }} ```test```{% endraw %}'
);
+ assert.equal(
+ page.prepare('{% raw %}Hello {{ "Bonjour" }} {% raw %}{% endraw %}```test```'),
+ '{% raw %}Hello {{ "Bonjour" }} {% raw %}{% endraw %}{% raw %}```test```{% endraw %}'
+ );
});
it('should not process math', function() {