feat(parser): skip comment

This commit is contained in:
syy11cn 2022-06-03 13:59:15 +08:00
parent cffd65ec2d
commit cd5ac19179
2 changed files with 6 additions and 2 deletions

View File

@ -5,7 +5,7 @@ import type { IImageOptions, IRunOptions, ParagraphChild } from 'docx'
import { HeadingLevel, ImageRun, Paragraph, TextRun } from 'docx' import { HeadingLevel, ImageRun, Paragraph, TextRun } from 'docx'
import type Token from 'markdown-it/lib/token' import type Token from 'markdown-it/lib/token'
import { StyleId } from '@md-report/types' import { StyleId } from '@md-report/types'
import { sliceInlineText } from './utils' import { CommentRegExp, sliceInlineText } from './utils'
export function parseInline(props: { tokens: Token[]; style?: StyleId; headingLevel?: number; isUL?: boolean; isOL?: boolean }): Paragraph { export function parseInline(props: { tokens: Token[]; style?: StyleId; headingLevel?: number; isUL?: boolean; isOL?: boolean }): Paragraph {
// Props. // Props.
@ -95,7 +95,9 @@ export function parseText(tokens: Token[]): TextRun {
break break
// Normal text. // Normal text.
default: default:
options = { ...options, text: token.content } // No output for comments.
if (!token.content.match(CommentRegExp))
options = { ...options, text: token.content }
} }
} }
}) })

View File

@ -59,3 +59,5 @@ export function sliceInlineText(tokens: Token[]): SliceResult {
} }
export const MathBlockRegExp = /^\$\$\n([^]*)\n\$\$$/ export const MathBlockRegExp = /^\$\$\n([^]*)\n\$\$$/
export const CommentRegExp = /^\<\!\-[^]*\-\>$/