|
@@ -89,7 +89,7 @@ const splitLine = (text) => {
|
|
|
return {
|
|
return {
|
|
|
type: 'element',
|
|
type: 'element',
|
|
|
tagName: 'span',
|
|
tagName: 'span',
|
|
|
- properties: { className: ['code-line'] },
|
|
|
|
|
|
|
+ properties: { className: [] },
|
|
|
children: [{ type: 'text', value: line }],
|
|
children: [{ type: 'text', value: line }],
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
@@ -109,7 +109,6 @@ const addNodePositionClosure = () => {
|
|
|
* @return {Element['children']}
|
|
* @return {Element['children']}
|
|
|
*/
|
|
*/
|
|
|
const addNodePosition = (ast) => {
|
|
const addNodePosition = (ast) => {
|
|
|
- // @ts-ignore
|
|
|
|
|
return ast.reduce((result, node) => {
|
|
return ast.reduce((result, node) => {
|
|
|
if (node.type === 'text') {
|
|
if (node.type === 'text') {
|
|
|
const value = /** @type {string} */ (node.value)
|
|
const value = /** @type {string} */ (node.value)
|
|
@@ -240,28 +239,28 @@ const rehypePrismGenerator = (refractor) => {
|
|
|
'showlinenumbers={false}',
|
|
'showlinenumbers={false}',
|
|
|
]
|
|
]
|
|
|
for (const [i, line] of codeLineArray.entries()) {
|
|
for (const [i, line] of codeLineArray.entries()) {
|
|
|
- // Code lines
|
|
|
|
|
|
|
+ // Default class name for each line
|
|
|
|
|
+ line.properties.className = ['code-line']
|
|
|
|
|
+
|
|
|
|
|
+ // Line number
|
|
|
if (
|
|
if (
|
|
|
(meta.toLowerCase().includes('showLineNumbers'.toLowerCase()) ||
|
|
(meta.toLowerCase().includes('showLineNumbers'.toLowerCase()) ||
|
|
|
options.showLineNumbers) &&
|
|
options.showLineNumbers) &&
|
|
|
!falseShowLineNumbersStr.some((str) => meta.toLowerCase().includes(str))
|
|
!falseShowLineNumbersStr.some((str) => meta.toLowerCase().includes(str))
|
|
|
) {
|
|
) {
|
|
|
line.properties.line = [(i + startingLineNumber).toString()]
|
|
line.properties.line = [(i + startingLineNumber).toString()]
|
|
|
- // @ts-ignore
|
|
|
|
|
line.properties.className.push('line-number')
|
|
line.properties.className.push('line-number')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Line highlight
|
|
// Line highlight
|
|
|
if (shouldHighlightLine(i)) {
|
|
if (shouldHighlightLine(i)) {
|
|
|
- // @ts-ignore
|
|
|
|
|
line.properties.className.push('highlight-line')
|
|
line.properties.className.push('highlight-line')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Diff classes
|
|
|
if (lang === 'diff' && toString(line).substring(0, 1) === '-') {
|
|
if (lang === 'diff' && toString(line).substring(0, 1) === '-') {
|
|
|
- // @ts-ignore
|
|
|
|
|
line.properties.className.push('deleted')
|
|
line.properties.className.push('deleted')
|
|
|
} else if (lang === 'diff' && toString(line).substring(0, 1) === '+') {
|
|
} else if (lang === 'diff' && toString(line).substring(0, 1) === '+') {
|
|
|
- // @ts-ignore
|
|
|
|
|
line.properties.className.push('inserted')
|
|
line.properties.className.push('inserted')
|
|
|
}
|
|
}
|
|
|
|
|
|