summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-markdown/lib/page.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-markdown/lib/page.js')
-rw-r--r--packages/gitbook-markdown/lib/page.js49
1 files changed, 29 insertions, 20 deletions
diff --git a/packages/gitbook-markdown/lib/page.js b/packages/gitbook-markdown/lib/page.js
index 12848ed..2cf0941 100644
--- a/packages/gitbook-markdown/lib/page.js
+++ b/packages/gitbook-markdown/lib/page.js
@@ -1,10 +1,10 @@
var _ = require('lodash');
var MarkupIt = require('markup-it');
-var gitbookSyntax = require('markup-it/syntaxes/gitbook');
+var gitbookSyntax = require('markup-it/syntaxes/markdown');
var RAW_START = '{% raw %}';
var RAW_END = '{% endraw %}';
-var gitbook = new MarkupIt(gitbookSyntax);
+var markdown = new MarkupIt(gitbookSyntax);
/**
* Escape a code block's content using raw blocks
@@ -26,31 +26,40 @@ function escape(str) {
*/
function preparePage(src) {
var levelRaw = 0;
+ var content = markdown.toContent(src, {
+ math: true,
+ template: true
+ });
- return gitbook.annotate(src, function(token) {
- var tokenType = token.getType();
-
- if (tokenType === MarkupIt.BLOCKS.TEMPLATE && tokenType === MarkupIt.STYLES.TEMPLATE) {
- var expr = token.getData().get('type');
- if (expr === 'raw') {
- levelRaw = levelRaw + 1;
- } else if (expr == 'endraw') {
- levelRaw = 0;
- }
-
- return true;
- }
+ var textMarkdown = markdown.toText(content, {
+ annotate: function(state, raw, token) {
+ var tokenType = token.getType();
- if (token.isBlock() && )
+ if (tokenType === MarkupIt.ENTITIES.TEMPLATE) {
+ var type = token.getData().get('type');
+ var expr = token.getAsPlainText();
+ if (type === 'expr') {
+ if (expr === 'raw') {
+ levelRaw = levelRaw + 1;
+ } else if (expr == 'endraw') {
+ levelRaw = 0;
+ }
+ }
+ }
+ if (
+ (tokenType === MarkupIt.BLOCKS.CODE || tokenType === MarkupIt.STYLES.CODE)
+ && levelRaw === 0
+ ) {
+ return escape(raw);
+ }
- if (tokenType !== MarkupIt.BLOCKS.CODE && tokenType !== MarkupIt.STYLES.CODE && levelRaw == 0) {
- return;
+ return raw;
}
-
- return escape(token.getRaw());
});
+
+ return textMarkdown;
}
module.exports = {