From cd5ac191795bf555f94c3bd9ab69aecc43654953 Mon Sep 17 00:00:00 2001 From: syy11cn Date: Fri, 3 Jun 2022 13:59:15 +0800 Subject: [PATCH] feat(parser): skip comment --- packages/parser/src/inline.ts | 6 ++++-- packages/parser/src/utils.ts | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/parser/src/inline.ts b/packages/parser/src/inline.ts index 74bb58a..cb9b891 100644 --- a/packages/parser/src/inline.ts +++ b/packages/parser/src/inline.ts @@ -5,7 +5,7 @@ import type { IImageOptions, IRunOptions, ParagraphChild } from 'docx' import { HeadingLevel, ImageRun, Paragraph, TextRun } from 'docx' import type Token from 'markdown-it/lib/token' 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 { // Props. @@ -95,7 +95,9 @@ export function parseText(tokens: Token[]): TextRun { break // Normal text. default: - options = { ...options, text: token.content } + // No output for comments. + if (!token.content.match(CommentRegExp)) + options = { ...options, text: token.content } } } }) diff --git a/packages/parser/src/utils.ts b/packages/parser/src/utils.ts index c15365a..a2efad4 100644 --- a/packages/parser/src/utils.ts +++ b/packages/parser/src/utils.ts @@ -59,3 +59,5 @@ export function sliceInlineText(tokens: Token[]): SliceResult { } export const MathBlockRegExp = /^\$\$\n([^]*)\n\$\$$/ + +export const CommentRegExp = /^\<\!\-[^]*\-\>$/