Просмотр исходного кода

feat: parse meta even when no lang is passed in

Timothy Lin 4 лет назад
Родитель
Сommit
02e6f5ea5a
1 измененных файлов с 5 добавлено и 3 удалено
  1. 5 3
      index.js

+ 5 - 3
index.js

@@ -58,18 +58,20 @@ const rehypePrism = (options) => {
     }
 
     const lang = getLanguage(node)
-    const meta = node.data && node.data.meta ? node.data.meta : ''
-    const shouldHighlightLine = calculateLinesToHighlight(meta)
+    let meta = node.data && node.data.meta ? node.data.meta : ''
 
     if (lang) {
       parent.properties.className = (parent.properties.className || []).concat('language-' + lang)
+      // Add lang to meta to allow line highlighting even when no lang is specified
+      meta = `${lang} ${meta}`
     }
 
+    const shouldHighlightLine = calculateLinesToHighlight(meta)
     const codeLineArray = splitLine(toString(node))
 
     for (const [i, line] of codeLineArray.entries()) {
       // Code lines
-      if (meta.includes('showLineNumbers') || options.showLineNumbers) {
+      if (meta.toLowerCase().includes('showLineNumbers'.toLowerCase()) || options.showLineNumbers) {
         line.properties.line = [(i + 1).toString()]
         line.properties.className = [`${line.properties.className} line-number`]
       }