Skip to content

Commit 3b5088f

Browse files
committed
init
0 parents  commit 3b5088f

File tree

10 files changed

+479
-0
lines changed

10 files changed

+479
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
node_modules
3+
*.log
4+
.temp
5+
TODOs.md
6+
.vscode

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Markdown-it Vuepress Code Snippet Enhanced
2+
3+
4+
## Why use this plugin?
5+
6+
- Specify your own language :boom:
7+
- Transclude any part of a file :boom:
8+
- Line highlighting extended from Vuepress :green_heart:
9+
10+
<br />
11+
12+
## Install
13+
14+
```sh
15+
npm i -D markdown-it-vuepress-code-snippet-enhanced
16+
```
17+
18+
---
19+
<br />
20+
21+
## Setup
22+
23+
In Vuepress `config.js` add the following:
24+
25+
```js
26+
markdown: {
27+
config: md => {
28+
md.use(require('markdown-it-vuepress-code-snippet-enhanced'))
29+
}
30+
}
31+
```
32+
33+
You can now import code snippets into your markdown files with the following syntax:
34+
35+
```md
36+
@[code](@/docs/code.js)
37+
@[code lang=ruby transclude={1-1}](@/docs/code.rb)
38+
@[code highlight={1-6} transcludeTag=style](@/docs/code.vue)
39+
@[code highlight={4,9,11-16} transcludeWith=:::](@/docs/code.vue)
40+
```
41+
42+
43+
44+
## Options
45+
46+
### Language
47+
You can specify any language for syntax highlighting as follows:
48+
```md
49+
@[code lang=ruby](@/docs/code.rb)
50+
@[code lang=csharp](@/docs/code.cs)
51+
```
52+
_Vuepress uses prismjs, so for proper syntax highlighting check prism.js docs._
53+
54+
<br/>
55+
56+
### Transclusion
57+
You can transclude a single or multiple parts of a file using `transclude`, `transcludeWith`, or `transcludeTag`.
58+
59+
#### transcludeWith
60+
For transcluding one or more parts of a file using comment lines and specify a unique pattern.
61+
```md
62+
@[code lang=ruby transcludeWith=|_|_|](@/docs/code.rb)
63+
@[code transcludeWith=:::](@/docs/code.js)
64+
@[code transcludeWith=++++](@/docs/code.h)
65+
```
66+
##### Example
67+
```rb
68+
require 'lib'
69+
require 'other'
70+
71+
# |_|_|
72+
def hello
73+
puts 'hello'
74+
puts 'vue'
75+
end
76+
# |_|_|
77+
```
78+
79+
#### transcludeTag
80+
Useful when working `Vue` single file components.
81+
```md
82+
@[code transcludeTag=template](@/docs/code.vue)
83+
@[code transcludeTag=script](@/docs/code.vue)
84+
@[code transcludeTag=style](@/docs/code.vue)
85+
```
86+
87+
#### transclude
88+
Use a range indicating the `start` and `end` lines. This option is inclusive.
89+
```md
90+
@[code transclude={5-13}](@/docs/code.js)
91+
```
92+
93+
94+
## Sample
95+
96+
### Input Markdown
97+
```
98+
@[code highlight={1-6} transcludeTag=style](@/docs/code.vue)
99+
```
100+
101+
### Source File
102+
```html
103+
<template>
104+
<div class="component"></div>
105+
</template>
106+
107+
<script>
108+
export default {
109+
mounted () {
110+
alert('yay!')
111+
}
112+
}
113+
</script>
114+
115+
<style lang="scss" scoped>
116+
.component {
117+
display: flex;
118+
}
119+
</style>
120+
```
121+
### Rendered Output
122+
123+
```css
124+
<style lang="scss" scoped>
125+
.component {
126+
display: flex;
127+
}
128+
</style>
129+
```

example.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = function autolink(state, silent) {
2+
var tail, linkMatch, emailMatch, url, fullUrl, token,
3+
pos = state.pos;
4+
5+
if (state.src.charCodeAt(pos) !== 0x3C /* < */ ) {
6+
return false;
7+
}
8+
9+
tail = state.src.slice(pos);
10+
11+
if (tail.indexOf('>') < 0) {
12+
return false;
13+
}
14+
}

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const codeSnippet = require('./src/plugin')
2+
3+
module.exports = codeSnippet

package-lock.json

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "markdown-it-import",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"dev": "node index.js",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "Fabio Anselmo <[email protected]>",
12+
"license": "MIT",
13+
"devDependencies": {
14+
"markdown-it": "^8.4.2",
15+
"markdown-it-prism": "^2.0.1"
16+
}
17+
}

0 commit comments

Comments
 (0)