Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(markdown): detect inline component followed non whitespace characters #1227

Merged
merged 8 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export const Codes = {
* null
*/
EOF: null,
/**
* ' '
*/
space: 32,
/**
* '"'
*/
Expand All @@ -24,13 +28,25 @@ export const Codes = {
*/
apostrophe: 39,
/**
* '`'
* '('
*/
backTick: 96,
openingParentheses: 40,
/**
* '\'
* ')'
*/
backSlash: 92,
closingParentheses: 41,
/**
* ','
**/
comma: 44,
/**
* '-'
*/
dash: 45,
/**
* '.'
*/
dot: 46,
/**
* ':'
*/
Expand All @@ -48,51 +64,39 @@ export const Codes = {
*/
greaterThan: 62,
/**
* '-'
*/
dash: 45,
/**
* '.'
*/
dot: 46,
/**
* ' '
* 'X'
*/
space: 32,
uppercaseX: 88,
/**
* '['
*/
openingSquareBracket: 91,
/**
* ']'
*/
closingSquareBracket: 93,
/**
* '{'
* '\'
*/
openingCurlyBracket: 123,
backSlash: 92,
/**
* '}'
* ']'
*/
closingCurlyBracket: 125,
closingSquareBracket: 93,
/**
* '('
* '_'
*/
openingParentheses: 40,
underscore: 95,
/**
* ')'
* '`'
*/
closingParentheses: 41,
backTick: 96,
/**
* '_'
* 'x'
*/
underscore: 95,
lowercaseX: 120,
/**
* 'X'
* '{'
*/
uppercaseX: 88,
openingCurlyBracket: 123,
/**
* 'x'
* '}'
*/
lowercaseX: 120
closingCurlyBracket: 125
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function tokenize (this: TokenizeContext, effects: Effects, ok: State, nok: Stat
}

function exit (code: Code): void | State {
if (!markdownLineEndingOrSpace(code) && code !== null && ![Codes.closingSquareBracket].includes(code)) {
if (!markdownLineEndingOrSpace(code) && ![Codes.EOF, Codes.closingSquareBracket, Codes.dot, Codes.comma].includes(code)) {
return nok(code)
}
effects.exit('componentText')
Expand Down
17 changes: 17 additions & 0 deletions test/features/parser-markdown.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, test, expect, assert } from 'vitest'
import { $fetch } from '@nuxt/test-utils'
import { visit } from 'unist-util-visit'

export const testMarkdownParser = () => {
describe('parser:markdown', () => {
Expand Down Expand Up @@ -68,5 +69,21 @@ export const testMarkdownParser = () => {
expect(parsed.body).toHaveProperty('children')
expect(parsed.body.children.length).toEqual(0)
})

test('inline component followed by dot or comma', async () => {
const parsed = await $fetch('/api/parse', {
method: 'POST',
body: {
id: 'content:index.md',
content: 'Inline component `:Comp` :Comp[works] beautifully, unless I put it before a :Comp[comma], or a :Comp[period].'
}
})

let compComponentCount = 0
visit(parsed.body, node => (node as any).tag === 'comp', () => {
compComponentCount += 1
})
expect(compComponentCount).toEqual(3)
})
})
}