mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
Add file name and any first line number in code block (fixed)
This commit is contained in:
@@ -220,6 +220,7 @@ pre
|
|||||||
background-color white
|
background-color white
|
||||||
&.CodeMirror
|
&.CodeMirror
|
||||||
height initial
|
height initial
|
||||||
|
flex-wrap wrap
|
||||||
&>code
|
&>code
|
||||||
flex 1
|
flex 1
|
||||||
overflow-x auto
|
overflow-x auto
|
||||||
@@ -229,6 +230,13 @@ pre
|
|||||||
padding 0
|
padding 0
|
||||||
border none
|
border none
|
||||||
border-radius 0
|
border-radius 0
|
||||||
|
&>span.filename
|
||||||
|
width 100%
|
||||||
|
border-radius: 5px 0px 0px 0px
|
||||||
|
margin -8px 100% 8px -8px
|
||||||
|
padding 0px 6px
|
||||||
|
background-color #777;
|
||||||
|
color white
|
||||||
&>span.lineNumber
|
&>span.lineNumber
|
||||||
display none
|
display none
|
||||||
font-size 1em
|
font-size 1em
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import {lastFindInArray} from './utils'
|
|||||||
const katex = window.katex
|
const katex = window.katex
|
||||||
const config = ConfigManager.get()
|
const config = ConfigManager.get()
|
||||||
|
|
||||||
function createGutter (str) {
|
function createGutter (str, fc) {
|
||||||
const lc = (str.match(/\n/g) || []).length
|
if(Number.isNaN(fc)) fc = 1
|
||||||
|
const lc = (str.match(/\n/g) || []).length + fc - 1
|
||||||
const lines = []
|
const lines = []
|
||||||
for (let i = 1; i <= lc; i++) {
|
for (let i = fc; i <= lc; i++) {
|
||||||
lines.push('<span class="CodeMirror-linenumber">' + i + '</span>')
|
lines.push('<span class="CodeMirror-linenumber">' + i + '</span>')
|
||||||
}
|
}
|
||||||
return '<span class="lineNumber CodeMirror-gutters">' + lines.join('') + '</span>'
|
return '<span class="lineNumber CodeMirror-gutters">' + lines.join('') + '</span>'
|
||||||
@@ -25,6 +26,12 @@ var md = markdownit({
|
|||||||
xhtmlOut: true,
|
xhtmlOut: true,
|
||||||
breaks: true,
|
breaks: true,
|
||||||
highlight: function (str, lang) {
|
highlight: function (str, lang) {
|
||||||
|
let delimiter = ":";
|
||||||
|
let langinfo = lang.split(delimiter);
|
||||||
|
let lang = langinfo[0];
|
||||||
|
let filename = langinfo[1] || "";
|
||||||
|
let fc = parseInt(langinfo[2],10);
|
||||||
|
|
||||||
if (lang === 'flowchart') {
|
if (lang === 'flowchart') {
|
||||||
return `<pre class="flowchart">${str}</pre>`
|
return `<pre class="flowchart">${str}</pre>`
|
||||||
}
|
}
|
||||||
@@ -32,7 +39,8 @@ var md = markdownit({
|
|||||||
return `<pre class="sequence">${str}</pre>`
|
return `<pre class="sequence">${str}</pre>`
|
||||||
}
|
}
|
||||||
return '<pre class="code">' +
|
return '<pre class="code">' +
|
||||||
createGutter(str) +
|
'<span class="filename">' + filename + '</span>' +
|
||||||
|
createGutter(str, fc) +
|
||||||
'<code class="' + lang + '">' +
|
'<code class="' + lang + '">' +
|
||||||
str +
|
str +
|
||||||
'</code></pre>'
|
'</code></pre>'
|
||||||
|
|||||||
Reference in New Issue
Block a user