Skip to content

Commit

Permalink
fix: a space is required between id block and url for references
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Dec 5, 2022
1 parent 2eaa426 commit 959cab0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
25 changes: 23 additions & 2 deletions index.compiler.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,11 @@ describe('links', () => {
})

it('should not link URL if it is nested inside an anchor tag', () => {
render(compiler('<a href="https://google.com">some text <span>with a link https://google.com</span></a>'))
render(
compiler(
'<a href="https://google.com">some text <span>with a link https://google.com</span></a>'
)
)

expect(root.innerHTML).toMatchInlineSnapshot(`
<a href="https://google.com">
Expand All @@ -903,7 +907,11 @@ describe('links', () => {
</a>
`)

render(compiler('<a href="https://google.com">some text <span>with a nested link <span>https://google.com</span></span></a>'))
render(
compiler(
'<a href="https://google.com">some text <span>with a nested link <span>https://google.com</span></span></a>'
)
)

expect(root.innerHTML).toMatchInlineSnapshot(`
<a href="https://google.com">
Expand Down Expand Up @@ -2859,6 +2867,19 @@ comment -->`)
</span>
`)
})

it('#465 misc regression test', () => {
render(compiler('hello [h]:m **world**'))

expect(root.innerHTML).toMatchInlineSnapshot(`
<span>
hello [h]:m
<strong>
world
</strong>
</span>
`)
})
})

describe('horizontal rules', () => {
Expand Down
57 changes: 28 additions & 29 deletions index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const LIST_LOOKBEHIND_R = /(?:^|\n)( *)$/
const CAPTURE_LETTER_AFTER_HYPHEN = /-([a-z])?/gi
const NP_TABLE_R = /^(.*\|?.*)\n *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*)\n?/
const PARAGRAPH_R = /^[^\n]+(?: \n|\n{2,})/
const REFERENCE_IMAGE_OR_LINK = /^\[([^\]]*)\]:\s*(\S+)\s*("([^"]*)")?/
const REFERENCE_IMAGE_OR_LINK = /^\[([^\]]*)\]:\s+(\S+)\s*("([^"]*)")?/
const REFERENCE_IMAGE_R = /^!\[([^\]]*)\] ?\[([^\]]*)\]/
const REFERENCE_LINK_R = /^\[([^\]]*)\] ?\[([^\]]*)\]/
const SQUARE_BRACKETS_R = /(\[|\])/g
Expand Down Expand Up @@ -897,12 +897,13 @@ function parseBlock(
return parse(content + '\n\n', state)
}

const parseCaptureInline: MarkdownToJSX.Parser<ReturnType<typeof parseInline>> =
(capture, parse, state: MarkdownToJSX.State) => {
return {
content: parseInline(parse, capture[1], state),
}
const parseCaptureInline: MarkdownToJSX.Parser<
ReturnType<typeof parseInline>
> = (capture, parse, state: MarkdownToJSX.State) => {
return {
content: parseInline(parse, capture[1], state),
}
}

function captureNothing() {
return {}
Expand Down Expand Up @@ -1766,36 +1767,34 @@ export function compiler(
}

// Object.keys(rules).forEach(key => {
// let { match, parse } = rules[key];
// let { _match: match, _parse: parse } = rules[key]

// rules[key]._match = (...args) => {
// const start = performance.now();
// const result = match(...args);
// const delta = performance.now() - start;
// rules[key]._match = (...args) => {
// const start = performance.now()
// const result = match(...args)
// const delta = performance.now() - start

// if (delta > 5)
// console.warn(
// `Slow match for ${key}: ${delta.toFixed(3)}ms, input: ${
// args[0]
// }`
// );
// if (delta > 5)
// console.warn(
// `Slow match for ${key}: ${delta.toFixed(3)}ms, input: ${args[0]}`
// )

// return result;
// };
// return result
// }

// rules[key]._parse = (...args) => {
// const start = performance.now();
// const result = parse(...args);
// const delta = performance.now() - start;
// rules[key]._parse = (...args) => {
// const start = performance.now()
// const result = parse(...args)
// const delta = performance.now() - start

// if (delta > 5)
// console.warn(`Slow parse for ${key}: ${delta.toFixed(3)}ms`);
// if (delta > 5)
// console.warn(`Slow parse for ${key}: ${delta.toFixed(3)}ms`)

// console.log(`${key}:parse`, `${delta.toFixed(3)}ms`, args[0]);
// console.log(`${key}:parse`, `${delta.toFixed(3)}ms`, args[0])

// return result;
// };
// });
// return result
// }
// })

if (options.disableParsingRawHTML !== true) {
rules.htmlBlock = {
Expand Down

0 comments on commit 959cab0

Please sign in to comment.