Skip to content

Commit

Permalink
Fix: failed commonmark examples 57 and 40, marked#1475
Browse files Browse the repository at this point in the history
  • Loading branch information
yahtnif committed May 6, 2019
1 parent 7fe1404 commit 4e612ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
19 changes: 13 additions & 6 deletions src/block-lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class BlockLexer {
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
html: new RegExp(html),
item: /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
lheading: /^([^\n]+)\n {0,3}(=|-){2,} *(?:\n+|$)/,
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
newline: /^\n+/,
paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading| {0,3}>|<\/?(?:tag)(?: +|\n|\/?>)|<(?:script|pre|style|!--))[^\n]+)*)/,
Expand Down Expand Up @@ -304,13 +304,20 @@ export class BlockLexer {

// code
if ((execArr = this.rules.code.exec(nextPart))) {
const lastToken = this.tokens[this.tokens.length - 1]
nextPart = nextPart.substring(execArr[0].length)
const code: string = execArr[0].replace(/^ {4}/gm, '')

this.tokens.push({
type: TokenType.code,
text: !this.options.pedantic ? this.options.rtrim(code, '\n') : code
})
// An indented code block cannot interrupt a paragraph.
if (lastToken && lastToken.type === 'paragraph') {
lastToken.text += `\n${execArr[0].trimRight()}`
} else {
const code = execArr[0].replace(/^ {4}/gm, '')
this.tokens.push({
type: TokenType.code,
codeBlockStyle: 'indented',
text: !this.options.pedantic ? this.options.rtrim(code, '\n') : code
})
}
continue
}

Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface Token {
footnote?: string
footnotes?: string[]
refname?: string
codeBlockStyle?: string
}

export interface BaseInlineRules {
Expand Down
3 changes: 2 additions & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export class Parser {
* Next Token
*/
protected next(): Token {
return (this.token = this.tokens.pop())
this.token = this.tokens.pop()
return this.token
}

/**
Expand Down

0 comments on commit 4e612ad

Please sign in to comment.