Skip to content

Commit

Permalink
fix: 修复相对路径错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
sj817 committed Aug 5, 2024
1 parent 849ad09 commit c486948
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{{style}}}
<link rel="stylesheet" href="{{{highlight}}}">
<link rel="stylesheet" href="{{{gitcss}}}">
<style>
.markdown-body {
box-sizing: border-box;
Expand All @@ -22,6 +19,9 @@
}
}
</style>
<style>{{{style}}}</style>
<style>{{{highlight}}}</style>
<style>{{{gitcss}}}</style>
</head>

<body>
Expand Down
51 changes: 27 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,37 @@ export default class Markdown {
*/
render (markdown: string): string {
const style = `
<style>
pre {
position: relative
}
pre code {
padding-left: 3.8em
}
.hljs-line::before {
content: attr(data-line-number)
display: inline-block
width: 2em
margin-left: -2.5em
text-align: right
color: #999
border-right: 1px solid #ddd
padding-right: 0.5em
}
.hljs .hljs-line {
display: block
padding-right: 0.5em
padding-left: 0.5em
}
</style>
pre {
position: relative;
}
pre code {
padding-left: 3.8em;
}
.hljs-line::before {
content: attr(data-line-number);
display: inline-block;
width: 2em;
margin-left: -2.5em;
text-align: right;
color: #999;
border-right: 1px solid #ddd;
padding-right: 0.5em;
}
.hljs .hljs-line {
display: block;
padding-right: 0.5em;
padding-left: 0.5em;
}
`

/** 判断下是否为路径 */
const htmlContent = marked(fs.existsSync(markdown) ? fs.readFileSync(markdown, 'utf-8') : markdown)
return mustache.render(this.template, { gitcss: this.gitcss, highlight: this.highlight, htmlContent, style })
const gitcss = fs.readFileSync(this.gitcss, 'utf-8')
const highlight = fs.readFileSync(this.highlight, 'utf-8')
return mustache.render(this.template, { gitcss, highlight, htmlContent, style })
}
}

Expand Down

0 comments on commit c486948

Please sign in to comment.