-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from guicassolato/webview-enhancements
Webview enhancements
- Loading branch information
Showing
9 changed files
with
361 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Tothom | ||
|
||
- [Hello World!](#hello-world) | ||
- [Interpolation](#interpolation) | ||
- [Multiline](#multiline) | ||
- [Compatibility](#compatibility) | ||
- [Unordered Lists](#unordered-lists) | ||
- [Ordered Lists](#ordered-lists) | ||
- [Task lists](#task-lists) | ||
- [Links](#links) | ||
|
||
## Hello World! | ||
|
||
```sh | ||
echo 'Hello World!' | ||
``` | ||
|
||
## Interpolation | ||
|
||
```sh | ||
echo "Current directory is $PWD" | ||
``` | ||
|
||
## Multiline | ||
|
||
```sh | ||
cat <<EOF | ||
This is a | ||
multiline | ||
code block | ||
EOF | ||
``` | ||
|
||
## Compatibility | ||
|
||
### Unordered Lists | ||
|
||
- Item 1 | ||
- Item 2 | ||
- Item 3 | ||
|
||
### Ordered Lists | ||
|
||
1. Item 1 | ||
2. Item 2 | ||
3. Item 3 | ||
|
||
### Task lists | ||
|
||
- [x] Item 1 | ||
- [ ] Item 2 | ||
- [ ] Item 3 | ||
|
||
### Links | ||
|
||
External [link](https://marketplace.visualstudio.com/items?itemName=guicassolato.tothom). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import hljs from 'highlight.js'; | ||
|
||
import * as terminal from './terminal'; | ||
|
||
const renderCodeBlock = (code: string, language: string): string => { | ||
const codeAttrs = (language !== "") ? ` class="language-${language}"` : ''; | ||
|
||
let link = ""; | ||
switch (language) { | ||
case 'bash': | ||
case 'sh': | ||
case 'zsh': | ||
link = `<a href="tothom://?code=${terminal.encodeTerminalCommand(code, true)}" class="tothom-code-action" title="Run in terminal">▶️</a>`; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return `<pre class="hljs"><code${codeAttrs}>${syntaxHighlight(code, language)}</code>${link}</pre>`; | ||
}; | ||
|
||
const syntaxHighlight = (code: string, language: string): string => { | ||
if (language && hljs.getLanguage(language)) { | ||
try { | ||
return hljs.highlight(code, { language: language, ignoreIllegals: true }).value; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
return engine.utils.escapeHtml(code); | ||
}; | ||
|
||
const taskLists = require('markdown-it-task-lists'); | ||
|
||
export const engine = require('markdown-it')({ | ||
html: true, | ||
linkify: true, | ||
typographer: true, | ||
highlight: renderCodeBlock | ||
}).use(taskLists); |
Oops, something went wrong.