Update dependency markdown-it-deflist to v2.1.0 (#561)

* Update dependency markdown-it-deflist to v2.1.0

* Include end line number into key

Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>

* Update src/components/markdown-renderer/utils/html-react-transformer.tsx

Co-authored-by: Erik Michelson <github@erik.michelson.eu>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
This commit is contained in:
renovate[bot] 2020-09-15 21:23:06 +02:00 committed by GitHub
parent 8842fff06f
commit d57f6577a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 17 deletions

View file

@ -61,7 +61,7 @@
"markdown-it-abbr": "1.0.4",
"markdown-it-anchor": "5.3.0",
"markdown-it-container": "3.0.0",
"markdown-it-deflist": "2.0.3",
"markdown-it-deflist": "2.1.0",
"markdown-it-emoji": "1.4.0",
"markdown-it-footnote": "3.0.2",
"markdown-it-front-matter": "0.2.1",

View file

@ -12,14 +12,14 @@ export interface TextDifferenceResult {
lastUsedLineId: number
}
export const calculateKeyFromLineMarker = (node: DomElement, lineKeys?: LineKeys[]): number|undefined => {
export const calculateKeyFromLineMarker = (node: DomElement, lineKeys?: LineKeys[]): string|undefined => {
if (!node.attribs || lineKeys === undefined) {
return
}
const key = node.attribs['data-key']
if (key) {
return Number(key)
return key
}
const lineMarker = node.prev
@ -27,40 +27,42 @@ export const calculateKeyFromLineMarker = (node: DomElement, lineKeys?: LineKeys
return
}
const lineInMarkdown = lineMarker.attribs['data-start-line']
if (lineInMarkdown === undefined) {
const startLineInMarkdown = lineMarker.attribs['data-start-line']
const endLineInMarkdown = lineMarker.attribs['data-end-line']
if (startLineInMarkdown === undefined || endLineInMarkdown === undefined) {
return
}
const line = Number(lineInMarkdown)
if (lineKeys[line] === undefined) {
const startLine = Number(startLineInMarkdown)
const endLine = Number(endLineInMarkdown)
if (lineKeys[startLine] === undefined || lineKeys[endLine] === undefined) {
return
}
return lineKeys[line].id
return `${lineKeys[startLine].id}_${lineKeys[endLine].id}`
}
export const findNodeReplacement = (node: DomElement, index: number, allReplacers: ComponentReplacer[], subNodeTransform: SubNodeTransform): ReactElement|null|undefined => {
export const findNodeReplacement = (node: DomElement, key: string, allReplacers: ComponentReplacer[], subNodeTransform: SubNodeTransform): ReactElement|null|undefined => {
return allReplacers
.map((componentReplacer) => componentReplacer.getReplacement(node, subNodeTransform))
.find((replacement) => replacement !== undefined)
}
export const renderNativeNode = (node: DomElement, key: number, transform: Transform): ReactElement => {
export const renderNativeNode = (node: DomElement, key: string, transform: Transform): ReactElement => {
if (node.attribs === undefined) {
node.attribs = {}
}
delete node.attribs['data-key']
return convertNodeToElement(node, key, transform)
return convertNodeToElement(node, key as unknown as number, transform)
}
export const buildTransformer = (lineKeys: (LineKeys[] | undefined), allReplacers: ComponentReplacer[]):Transform => {
const transform: Transform = (node, index) => {
const nativeRenderer = (subNode: DomElement, subKey: number) => renderNativeNode(subNode, subKey, transform)
const nativeRenderer = (subNode: DomElement, subKey: string) => renderNativeNode(subNode, subKey, transform)
const subNodeTransform:SubNodeTransform = (subNode, subIndex) => transform(subNode, subIndex, transform)
const key = calculateKeyFromLineMarker(node, lineKeys) ?? -index
const key = calculateKeyFromLineMarker(node, lineKeys) ?? (-index).toString()
const tryReplacement = findNodeReplacement(node, key, allReplacers, subNodeTransform)
if (tryReplacement === null) {
return null

View file

@ -8714,10 +8714,10 @@ markdown-it-container@3.0.0:
resolved "https://registry.yarnpkg.com/markdown-it-container/-/markdown-it-container-3.0.0.tgz#1d19b06040a020f9a827577bb7dbf67aa5de9a5b"
integrity sha512-y6oKTq4BB9OQuY/KLfk/O3ysFhB3IMYoIWhGJEidXt1NQFocFK2sA2t0NYZAMyMShAGL6x5OPIbrmXPIqaN9rw==
markdown-it-deflist@2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/markdown-it-deflist/-/markdown-it-deflist-2.0.3.tgz#5727db04184d3cb2bc6ee4a9641e3a1091d5fd6f"
integrity sha512-/BNZ8ksW42bflm1qQLnRI09oqU2847Z7MVavrR0MORyKLtiUYOMpwtlAfMSZAQU9UCvaUZMpgVAqoS3vpToJxw==
markdown-it-deflist@2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/markdown-it-deflist/-/markdown-it-deflist-2.1.0.tgz#50d7a56b9544cd81252f7623bd785e28a8dcef5c"
integrity sha512-3OuqoRUlSxJiuQYu0cWTLHNhhq2xtoSFqsZK8plANg91+RJQU1ziQ6lA2LzmFAEes18uPBsHZpcX6We5l76Nzg==
markdown-it-emoji@1.4.0:
version "1.4.0"