Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
update mkslides
  • Loading branch information
jaywhj authored Nov 30, 2024
1 parent 210552a commit 4103f6c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 29 deletions.
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,32 @@ Thanks to both of them for their open source contributions.
### Use MkSlides

```python
mkslides build docs/demo-mkslides.md
mkslides build docs/demo.md
mkslides build docs/
```



#### preprocessing

Just turn on the switch of `preproc.py` in `mkslides.yml`.



### Use reveal-md

```bash
reveal-md docs/demo-mkslides.md --static _site
reveal-md docs/demo.md --static _site
```



#### preprocessing

Compare the difference between `demo-preprocessing.md` and `demo-mkslides.md`.
You need to add the path of `preproc.js` to the build command.

```bash
reveal-md --preprocessor preproc.js docs/demo-preprocessing.md --static _site
reveal-md --preprocessor preproc.js docs/demo.md --static _site
```


Expand All @@ -48,21 +55,21 @@ reveal-md --preprocessor preproc.js docs/demo-preprocessing.md --static _site

```bash
.
├── _site # reveal-md static site generated after a build, it is regenerated every time it is built.
├── site # MkSlides static site generated after a build, it is regenerated every time it is built.
├── docs # markdown document directory
│ ├── demo-mkslides.md
│ └── demo-preprocessing.md
├── _site # reveal-md static site generated after a build
├── site # MkSlides static site generated after a build
├── docs # markdown document
│ └── demo.md
├── plugin # plugin directory
│ ├── reveal.js-menu
│ │ └──menu.js
│ ├── other-plugin
│ │ └──other-plugin.js
│ └── plugin.js # for reveal-md
├── reveal-md.json # for reveal-md
├── reveal.json # for reveal-md
├── preproc.js
└── mkslides.yml # for MkSlides
│ └── other-plugin
│ └──other-plugin.js
├── plugin.js # for reveal-md
├── preproc.js # for reveal-md
├── reveal-md.json # for reveal-md
├── reveal.json # for reveal-md
├── preproc.py # for MkSlides
└── mkslides.yml # for MkSlides
```


Expand Down
4 changes: 3 additions & 1 deletion mkslides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ slides:
separator: ^\s*<!--h-->\s*$
separator_vertical: ^\s*<!--v-->\s*$
separator_notes: "^Notes?:"
separator_charset: utf-8
charset: utf-8
preprocess_script: preproc.py # Auto-generate slides based on headings, no more need to manually add separators.

revealjs:
width: 1280
Expand All @@ -16,6 +17,7 @@ revealjs:
navigationMode: linear # default、linear、grid
slideNumber: c/t # true、false、h.v、h/v、c、c/t
showSlideNumber: speaker # all、print、speaker
pdfSeparateFragments: false

# Setting up tags to ignore for katex typesetting math formulas
katex:
Expand Down
6 changes: 6 additions & 0 deletions plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
options.plugins.push(
RevealMermaid,
RevealPlantUML,
RevealMenu,
RevealChart
);
21 changes: 10 additions & 11 deletions preproc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@
1-2 level headings, add horizontal page break: <!--h-->
3-6 level headings, add vertical page break: <!--v-->
This is my own rules of use, relatively reasonable, have a good structure and logic, especially when showing the overview view of the slides, or when the slide table of contents, you can see the clear structure, if you don't like it, you can modify it as you like.
This is my own rules of use, have a good structure and logic, especially when showing the overview view of the slides, or when the slide table of contents, you can see the clear structure, if you don't like it, you can modify it as you like.
*/
module.exports = (markdown, options) => {
return new Promise((resolve, reject) => {
var first_time = true;
var firstHeadingFound = false;
return resolve(
markdown
.split('\n')
.map((line, index) => {
if (!/^#/.test(line) || index === 0)
return line;

if (first_time) { //ignore the separator before the first heading
first_time = false;
return line;
const stripped = line.trimStart();
if (stripped.startsWith('#')) {
if (firstHeadingFound) {
return (stripped.split(' ')[0].length <= 2 ? '\n<!--h-->\n\n' + line : '\n<!--v-->\n\n' + line);
} else {
firstHeadingFound = true;
}
}
return line;

if (/^\s*#{1,2}\s+/.test(line))
return '\n<!--h-->\n\n' + line;
else
return '\n<!--v-->\n\n' + line;
})
.join('\n')
);
Expand Down
23 changes: 23 additions & 0 deletions preproc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'''
Preprocessing, automatically adding page breaks to headings:
1-2 level headings, add horizontal page break: <!--h-->
3-6 level headings, add vertical page break: <!--v-->
This is my own rules of use, have a good structure and logic, especially when showing the overview view of the slides, or when the slide table of contents, you can see the clear structure, if you don't like it, you can modify it as you like.
'''

def preprocess(markdown_text: str) -> str:
lines = markdown_text.split('\n')
result = []
first_heading_found = False

for index, line in enumerate(lines):
stripped = line.lstrip()
if stripped.startswith('#'):
if first_heading_found:
result.append('\n<!--h-->\n' if len(stripped.split()[0]) <= 2 else '\n<!--v-->\n')
else:
first_heading_found = True
result.append(line)

return '\n'.join(result)
2 changes: 1 addition & 1 deletion reveal-md.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"plugin/reveal.js-menu/menu.js",
"plugin/chart/chart.min.js",
"plugin/chart/plugin.js",
"plugin/plugin.js"
"plugin.js"
]
}

0 comments on commit 4103f6c

Please sign in to comment.