Skip to content

Commit 254a7bc

Browse files
committed
Update checkbox style & upgrade MathJax
1 parent a882461 commit 254a7bc

File tree

5 files changed

+715
-116
lines changed

5 files changed

+715
-116
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@
3131
+ Support spoiler
3232
+ Support -b to enable hard-break mode
3333
+ Specify the start line number for code block
34-
+ Automatically generate `<title>`
34+
+ Automatically generate `<title>` according to the first `<h1>`
35+
+ `v0.0.8`
36+
+ Fix bug: line number should start at 1 not 0
37+
+ Modify index.md
38+
+ Remove unused dependencies
39+
+ Checkbox style follows hackmd
40+
+ Render MathJax directly at conversion time instead of front-end browser

layout.html

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,6 @@
44
<head>
55
<title>{{title}}</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
7-
<script>
8-
MathJax = {
9-
loader: { load: ['[tex]/enclose'] },
10-
tex2jax: {
11-
packages: ['base'], // extensions to use
12-
inlineMath: [ // start/end delimiter pairs for in-line math
13-
['\\(', '\\)']
14-
],
15-
displayMath: [ // start/end delimiter pairs for display math
16-
['$$', '$$'],
17-
['\\[', '\\]']
18-
],
19-
processEscapes: true, // use \$ to produce a literal dollar sign
20-
processEnvironments: true, // process \begin{xxx}...\end{xxx} outside math mode
21-
processRefs: true, // process \ref{...} outside of math mode
22-
digits: /^(?:[0-9]+(?:\{,\}[0-9]{3})*(?:\.[0-9]*)?|\.[0-9]+)/,
23-
// pattern for recognizing numbers
24-
tags: 'none', // or 'ams' or 'all'
25-
tagSide: 'right', // side for \tag macros
26-
tagIndent: '0.8em', // amount to indent tags
27-
useLabelIds: true, // use label name rather than tag for ids
28-
maxMacros: 1000, // maximum number of macro substitutions per expression
29-
maxBuffer: 5 * 1024, // maximum size for the internal TeX string (5K)
30-
baseURL: // URL for use with links to tags (when there is a <base> tag in effect)
31-
(document.getElementsByTagName('base').length === 0) ?
32-
'' : String(document.location).replace(/#.*$/, ''),
33-
formatError: // function called when TeX syntax errors occur
34-
(jax, err) => jax.formatError(err)
35-
},
36-
processEscapes: true
37-
};
38-
</script>
397
<style>
408
:root {
419
--body-background: #f0f0f0;
@@ -98,6 +66,16 @@
9866
padding-left: 2rem;
9967
}
10068

69+
li.task-list-item{
70+
list-style-type: none;
71+
}
72+
73+
input.task-list-item-checkbox{
74+
float: left;
75+
margin: .31em 0 .2em -1.3em !important;
76+
vertical-align: middle;
77+
}
78+
10179
main {
10280
background-color: #fff;
10381
box-sizing: border-box;
@@ -356,7 +334,7 @@
356334
<main>
357335
{{main}}
358336
</main>
359-
<script id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" async></script>
337+
<!--highlight-->
360338
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
361339
<script
362340
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/highlightjs-line-numbers.min.js"></script>
@@ -450,9 +428,9 @@
450428
}
451429

452430
if (lang[2]) {
453-
let line = 0;
431+
let line;
454432
if (lang[3] === '') {
455-
line = 0;
433+
line = 1;
456434
} else if (lang[3] === '+') {
457435
line = lastLine + 1;
458436
} else {

lib/converter.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import fs from 'fs'
22
import path from 'path'
33
import { MarkdownItYAMLMetadata } from './yaml-metadata'
44
import { MarkdownItContainer } from './container'
5+
import { MarkdownItCheckbox } from './checkbox'
6+
import MarkdownIt from 'markdown-it/lib'
57

6-
// const MarkdownItContainer = require('markdown-it-container')
7-
const MarkdownIt = require('markdown-it')
88
const MarkdownItSub = require('markdown-it-sub')
99
const MarkdownItSup = require('markdown-it-sup')
1010
const MarkdownItFootnote = require('markdown-it-footnote')
@@ -14,18 +14,17 @@ const MarkdownItEmoji = require('markdown-it-emoji')
1414
const MarkdownItIns = require('markdown-it-ins')
1515
const MarkdownItMark = require('markdown-it-mark')
1616
const MarkdownItImsize = require('markdown-it-imsize')
17-
const MarkdownItMathJax = require('markdown-it-mathjax')
17+
const MarkdownItMathJax3 = require('markdown-it-mathjax3')
1818
const MarkdownItTOC = require('markdown-it-table-of-contents')
1919
const MarkdownItAnchor = require('markdown-it-anchor')
2020
const MarkdownItRuby = require('markdown-it-ruby')
21-
const MarkdownItCheckbox = require('markdown-it-checkbox')
2221
const htmlEncode = require('htmlencode').htmlEncode;
2322

2423
export class Convert {
2524
src: Array<string>
2625
dest: string
2726
layout: string
28-
md: any
27+
md: MarkdownIt
2928
title: string
3029

3130
constructor(src: Array<string>, dest: string, layout: string, hardBreak: boolean) {
@@ -41,31 +40,29 @@ export class Convert {
4140
linkify: true,
4241
typographer: true
4342
})
44-
.use(MarkdownItMathJax())
45-
.use(MarkdownItYAMLMetadata, (option: any) => {
46-
if ('title' in option) {
47-
this.title = option.title as string
48-
}
49-
})
43+
.use(MarkdownItMathJax3)
5044
.use(MarkdownItSub)
5145
.use(MarkdownItSup)
5246
.use(MarkdownItFootnote)
5347
.use(MarkdownItDeflist)
5448
.use(MarkdownItAbbr)
5549
.use(MarkdownItMark)
5650
.use(MarkdownItEmoji)
57-
.use(MarkdownItContainer)
5851
.use(MarkdownItIns)
5952
.use(MarkdownItImsize)
6053
.use(MarkdownItTOC, {
6154
markerPattern: /^\[toc\]/im,
6255
includeLevel: [1, 2, 3, 4]
6356
})
57+
.use(MarkdownItYAMLMetadata, (option: any) => {
58+
if ('title' in option) {
59+
this.title = option.title as string
60+
}
61+
})
6462
.use(MarkdownItAnchor)
6563
.use(MarkdownItRuby)
66-
.use(MarkdownItCheckbox, {
67-
divWrap: true
68-
})
64+
.use(MarkdownItContainer)
65+
.use(MarkdownItCheckbox)
6966
}
7067

7168
// @param html: html string

0 commit comments

Comments
 (0)