Coder Social home page Coder Social logo

zhaouv / vscode-markdown-everywhere Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 2.0 1.03 MB

Embed and highlight and preview markdown in any language which support line-comment or block-comment for vscode.

Home Page: https://marketplace.visualstudio.com/items?itemName=zhaouv.vscode-markdown-everywhere

License: Apache License 2.0

JavaScript 95.48% C 0.76% Julia 0.87% MATLAB 0.77% Python 1.04% TeX 1.08%
vscode vscode-extension markdown embedded highlight

vscode-markdown-everywhere's Introduction

Markdown Everywhere

Embed and highlight and preview markdown in any language which support line-comment or block-comment for vscode. Also used for interpreting text as markdown.

e.g. Quickly preview LaTeX/ Highlight python markdown cell/ Highlight julia markdown doc string

Embed & Highlight

preview


Preview

Five mode

  • splitter: ignore source code part and put <hr> as splitter
  • ignored: ignore source code part
  • fenced: keep source code as fenced code
  • folded: keep source code as folded fenced code
  • raw: do nothing (for working with preview-inject)

splitter Help organize information
ignored
fenced
folded
raw

change it at settings.json - preview-mode

using preview-mode-language could setting for respective languages

provide setting to open preview automatically for listed languages

Preview Inject

Do some actions in parsing, only support to do some replacing before parse markdown to html now.

settings.json for quickly LaTeX previewing.

    "markdown-everywhere.preview-mode-language": {"latex":"raw"},
    "markdown-everywhere.preview-mode-inject": [
        {"language":"latex","path":".*","beforeSource":" let {src,options}=args\n const lines = src.split(/\\r?\\n|\\r\\n?/);\n let lino = -1;\n let currentOffset = 0;\n \n while (++lino < lines.length) {\n let pa=null;\n let line = lines[lino];\n\n // MD remove `\\label`, do not change number of lines, directly replace\n line=line.replace(/\\\\label{.*?}/g,'')\n\n // MD fix equation, add 3 more lines. fix offset for trace\n pa=/\\\\begin{(equation|display|alignat|aligned|align|multline|flalign)}/\n if (pa.exec(line)){\n line=line.replace(pa,(m)=>'\\n\\n$$\\n'+m)\n currentOffset+=3\n options.offset.push([lino + currentOffset, currentOffset])\n }\n\n // MD fix equation\n pa=/\\\\end{(equation|display|alignat|aligned|align|multline|flalign)}/\n if (pa.exec(line)){\n line=line.replace(pa,(m)=>m+'\\n$$\\n\\n')\n currentOffset+=3\n options.offset.push([lino + currentOffset, currentOffset])\n }\n\n lines[lino] = line;\n }\n return lines.join('\\r\\n');\n \n "}
    ],

The JSON generated from issue. More applications may be listed in the issue.

Extract Markdown

Command "Extract as Markdown to Clipboard" (also in right-mouse-click context menu.)

Convert selection into Markdown format according to the rules and preview mode, place it into the clipboard.

Can be used to copy Markdown from formats similar to JSDoc, automatically ignoring the * at the beginning of each line.

Enhancing-typing

whileSymbol or whileRegExp (if whileSymbol undefined) will be used for enhancing typing.
There will be some onEnterRules pushed to markdown.
So it will also affect the editing of normal markdown files.
You can turn off it in "settings.json".

onEnterRules checks the previous line, so it does not work on the first line of a markdown region.

Example:

// MD the first line
// MD the second line

After pressing enter at "e", it will automatically append "// MD ".

// MD the first line
// MD the second line
// MD 

change it at "settings.json"

Recommended Color

You can put those into "settings.json" to adjust the color.
So that markdown can be easily distinguished from both code and comments.

"editor.tokenColorCustomizations": {
    "[Default Dark+]": {
        "textMateRules": [
            {
                "scope": "meta.embedded.block.everywhere.md markup.heading, meta.embedded.block.everywhere.md markup.bold",
                "settings": {
                    "foreground": "#61aa71",
                }
            },
            {
                "scope": "meta.embedded.block.everywhere.md punctuation.definition.list.begin.markdown, meta.embedded.block.everywhere.md entity.name.tag",
                "settings": {
                    "foreground": "#599aa5",
                }
            },
            {
                "scope": "meta.embedded.block.everywhere.md entity.other.attribute-name",
                "settings": {
                    "foreground": "#98bdc4",
                }
            },
            {
                "scope": "meta.embedded.block.everywhere.md markup.inline.raw, meta.embedded.block.everywhere.md string",
                "settings": {
                    "foreground": "#ceca8b",
                }
            },
            {
                "scope": "meta.embedded.block.everywhere.md, meta.embedded.block.everywhere.md meta.embedded",
                "settings": {
                    "foreground": "#9abb87",
                }
            }
        ]
    }
}

Supported List

(note that some languages require that you install an VS Code extension that provides a grammar for that language)

Rule Type Example Languages
number-sign-MD LRSW # MD # title
# MD content
coffeescript
dockerfile
git-commit
git-rebase
diff
ignore
properties
makefile
perl
perl6
powershell
python
r
ruby
shellscript
yaml
cython
julia
cmake
number-sign LRSM # [markdown]
# # title
# content
coffeescript
dockerfile
git-commit
git-rebase
diff
ignore
properties
makefile
perl
perl6
powershell
python
r
ruby
shellscript
yaml
cython
julia
cmake
slash-star MR /* [markdown]
 * # title
 * content
 */
c
cpp
csharp
css
go
groovy
hlsl
java
javascriptreact
javascript
json
jsonc
less
objective-c
objective-cpp
php
rust
scss
shaderlab
sql
swift
typescript
typescriptreact
antlr
double-slash-MD LRSW // MD # title
// MD content
c
cpp
csharp
fsharp
go
groovy
hlsl
java
javascriptreact
javascript
json
jsonc
less
objective-c
objective-cpp
php
rust
scss
shaderlab
swift
typescript
typescriptreact
antlr
qasm-lang
double-slash LRSM // [markdown]
// # title
// content
c
cpp
csharp
fsharp
go
groovy
hlsl
java
javascriptreact
javascript
json
jsonc
less
objective-c
objective-cpp
php
rust
scss
shaderlab
swift
typescript
typescriptreact
antlr
qasm-lang
percentage-MD LRSW % MD # title
% MD content
matlab
bibtex
tex
latex
percentage LRSM % [markdown]
% # title
% content
matlab
bibtex
tex
latex
number-sign-double-percentage LRSM # %% [markdown]
# # highlight python markdown cell
# for the vscode-python data-science feature
coffeescript
dockerfile
git-commit
git-rebase
diff
ignore
properties
makefile
perl
perl6
powershell
python
r
ruby
shellscript
yaml
cython
julia
cmake
triple-quote BR """
    bar(x[, y])

julia standard markdown doc
"""
function bar(x, y) ...
julia
python
whitespace-triple-quote MR def abc():
    """
    xxx xxx
    xxx xxx
    """
    ...
julia
python
brace-dash BR {- [markdown]
# title
content-}
haskell
purescript
double-dash-MD LRSW -- MD # title
-- MD content
haskell
purescript
double-dash LRSM -- [markdown]
-- # title
% content
haskell
purescript
double-slash-exclamation LRSW //! # title
//! content
rust
triple-slash LRSW /// # title
/// content
rust
slash-start-exclamation BR /!
# My Crate
/
rust

Customize

Imitate rules and add new rules to "settings.json". And then run command "Build Markdown Embedding Rules" and then reload (press "F1", type "Build Markdown Embedding Rules" and "Reload Window"). And you need to run build command again when you update this extension.

Save the first element defaultRules to keep default rules. Remove to only use customized rules. Example:

"markdown-everywhere.customized-rules": [
    "defaultRules",
    {
        "name": "number-sign-equals",
        "beginRegExp": "#=\\s*\\[markdown\\]",
        "endRegExp": "=#",
        "example": "#= [markdown]<br># title<br>content<br>=#",
        "languages": [
            { "name": "julia", "source": "source.julia" }
        ]
    }
]

Rules

There are 4 types of rules, corresponding to 4 implementations

LRSW
line rule starts with the mark
whileRegExp

// MD connecting line-comment
// MD each line starts with the mark
rule={
    name: "double-slash-MD",
    whileRegExp: "// MD",
    example: "// MD # title<br>// MD content<br>",
    languages: [
        ...languages.filter(l => l.comments.lineComment === "//"),
        { name: "antlr", source: "source.antlr" },
        { name: "qasm-lang", source: "source.qasm" },
    ]
}

BR
block rule
beginRegExp+endRegExp

May introduce incorrect rendering, for example, use """ as markdown content in the follow demo

""" [markdown]
block comment starts with a start mark
and finally a end mark
"""
rule={
    name: "triple-quote",
    beginRegExp: "\"\"\"\\s*\\[markdown\\]",
    endRegExp: "\"\"\"",
    example: "\"\"\" [markdown]<br># title<br>content<br>\"\"\"",
    languages: [
        ...languages.filter(l => JSON.stringify(l.comments.blockComment||"") === JSON.stringify(["\"\"\"", "\"\"\""])),
    ]
}

preview will break in a situation like this, the current preview does not parse the statements

a="""
asd
"""

you can custom rules without defaultRules to close the triple-quote rule

MR
mixed rule
beginRegExp+whileRegExp+endRegExp

May introduce incorrect rendering, for example, use */ as markdown content in the follow demo

/* [markdown]
 * block comment starts with a start mark
 * and each line starts with the mark
 * and finally a end mark
 */
rule={
    name: "slash-star",
    beginRegExp: "/\\*\\s*\\[markdown\\]",
    whileRegExp: "\\*(?!/)",
    whileSymbol: "*",
    endRegExp: "\\*/",
    example: "/* [markdown]<br>&nbsp;* # title<br>&nbsp;* content<br>&nbsp;*/<br>",
    languages: [
        ...languages.filter(l => JSON.stringify(l.comments.blockComment||"") === JSON.stringify(["/*","*/"])),
        { name: "antlr", source: "source.antlr" },
    ]
}

LRSM
line rule with a start mark
beginRegExp+whileRegExp

// [markdown]
// some connecting normal line-comment 
// starts with a start mark (which is normaly a line-comment)
rule={
    name: "double-slash",
    beginRegExp: "//\\s*\\[markdown\\]",
    whileRegExp: "//",
    example: "// [markdown]<br>// # title<br>// content<br>",
    languages: [
        ...languages.filter(l => l.comments.lineComment === "//"),
        { name: "antlr", source: "source.antlr" },
        { name: "qasm-lang", source: "source.qasm" },
    ]
}

There is bug for this case. The following first line will be highlighted as comment. I haven't figured out the mechanism yet. So please put a empty line after these.


Extending from my pr in vscode-python (issue/pr).

vscode-markdown-everywhere's People

Contributors

cdfa avatar zhaouv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

bal-sm cdfa

vscode-markdown-everywhere's Issues

Rust support for triple slash comments

Good morning!

Rust uses a triple slash at the beginning of doc comments. Doc comments are interpreted as Markdown when the Rust code is sent to crates.io. I'm trying to figure out how best to add a rule for triple slashes but so far my attempts to modify the double slash rule from vscode-markdown-everywhere's docs have failed. I would assume adding triple slash support would be simple. Can anyone suggest how to achieve it?

Thanks!

Error when creating a new profile

Type: Bug

Settings -> Profiles -> Create Profile...
Copy from: Default
All checkboxes checked

Error message:
A filesystem provider for the scheme 'userdataprofileexport' is already registered.

Extension version: 0.0.12
VS Code version: Code 1.81.1 (6c3e3dba23e8fadc360aed75ce363ba185c49794, 2023-08-09T22:40:25.698Z)
OS version: Darwin arm64 22.6.0
Modes:

System Info
Item Value
CPUs Apple M1 (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 2, 2, 2
Memory (System) 16.00GB (0.20GB free)
Process Argv --crash-reporter-id 10d14be0-dcda-463f-b86e-60e029851af0
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vstes627cf:30244335
vslsvsres303:30308271
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vsdfh931:30280409
vshan820:30294714
vstes263:30335439
vscoreces:30445986
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
pythonvs932:30410667
vsclangdc:30486549
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
vsccc:30803844
3biah626:30602489
89544117:30613380
a9j8j154:30646983
showlangstatbar:30737416
03d35959:30757346
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
gsofb:30804716
pythonnosmt12:30797651
pythonidxptcf:30805731
pythonnoceb:30805159
dsvsc013:30795093
dsvsc014:30804076
diffeditorv2:30821572

[Feature request] Building custom rules on install

Hi, I am very happy that this extension allows me to add custom rules for markdown comments. This allows me to add support for Haskell.
I wonder if it's possible to detect if any custom rules have been set when the extensions is installed/enabled and immediately build the embedding rules.
I want to recommend others view my repository using the preview from this extension and it would be nice if they don't need to build the rules themselves and reload extensions, so it's a more seamless experience.

Latex Support

Hi, thanks for the extension - have been looking for something like it for a long time.

I wonder how hard it would be to add some latex support to it? It looks like neither the syntax highlighter nor the markdown preview handle it.

(Would be happy to help out with this, too, though I don't have much experience with VSCode Extension development.)

Highlighting quotes, strikethrough, and math formulas

Quotes, strikethrough, and math formulas (inline or standalone) are also quite common when we write markdown in additional to bold, italic, and headers. Would you like to add their syntax highlighting as well in the source code? Really appreciate it!

Notice

This extension is extending my pr in vscode-python (issue/pr).

To embed and highlight and preview markdown in any language which support line-comment or block-comment.

Incompatible With Lots of Extensions

A few examples:

  • Argdown
  • Markdown Preview Enhanced
  • Markdown All-In-One

When any of these (and likely many others) are installed and enabled at the same time, VSCode freezes up. It's apparently not just only an issue for me; I recommended Markdown Everywhere to someone else and they ran into the problem immediately.

I like this extension so much that I just don't use the above, but I imagine these conflicts should at least be documented if they can't be addressed - a couple of the above examples have millions of users.

Support `number-sign-double-percentage` in more languages

I like this extension very much. But I should recommend supporting number-sign-double-percentage instead of other options in more languages. This is actually a standard way of declaring cells and writing markdown comments in scripts dating back to Eclipse and Spider IDE and is widely supported by many editors and tools including Atom - Hydrogen, Jupytext, Visual Studio - Python Tools and PyCharm alongside VSCode - Jupyter. This is called percent format according to Jupytext.

[LITTLE BUG] Same markdown => Result at two places rendered differently!

I use in a Python program the same source-markdown at two places but it is different rendered (see attached image)
Setting is preview-mode: Ignored

See attached image

  • The two green source-markdown parts are identically GREEN(1) above and below

RESULT (red numbers)

  • RED(1) and RED(2) are rendered differently, but RED(2) should look same as RED(1) with the last list entry indented.
  • RED(3) is the default Python help from VSC and this is also rendered correct like RED(1)

Empty spaces in markdown should normally not influence/change the rendering result.
issue_markdown

Preview Inject

quickly preview latex

function printInjectJson() {
    
    let fff=()=>{

        let {src,options}=args
        const lines = src.split(/\r?\n|\r\n?/);
        let lino = -1;
        let currentOffset = 0;
        
        while (++lino < lines.length) {
            let pa=null;
            let line = lines[lino];

            // MD remove `\label`, do not change number of lines, directly replace
            line=line
            .replace(/\\label{.*?}/g,'')
            .replace(/\\chapter{(.*?)}/g,'# $1')
            .replace(/\\section{(.*?)}/g,'## $1')
            .replace(/\\subsection{(.*?)}/g,'### $1')
            .replace(/\\subsubsection{(.*?)}/g,'#### $1')
            .replace(/\\paragraph{(.*?)}/g,'##### $1')
            .replace(/\\subparagraph{(.*?)}/g,'##### $1')

            // MD fix equation, add 3 more lines. fix offset for trace
            pa=/\\begin{(equation|display|alignat|aligned|align|multline|flalign)}/
            if (pa.exec(line)){
                line=line.replace(pa,(m)=>'\n\n$$\n'+m)
                currentOffset+=3
                options.offset.push([lino + currentOffset, currentOffset])
            }

            // MD fix equation
            pa=/\\end{(equation|display|alignat|aligned|align|multline|flalign)}/
            if (pa.exec(line)){
                line=line.replace(pa,(m)=>m+'\n$$\n\n')
                currentOffset+=3
                options.offset.push([lino + currentOffset, currentOffset])
            }

            lines[lino] = line;
        }
        return lines.join('\r\n');
        
    }

    var sss=fff.toString().slice(7,-2).replace(/ +/g,' ')
    var ooo={"language":"latex","path":".*","beforeSource":sss}
    console.log(JSON.stringify(ooo))

}
printInjectJson()
    "markdown-everywhere.preview-mode-language": {"latex":"raw"},
    "markdown-everywhere.preview-mode-inject": [
        {"language":"latex","path":".*","beforeSource":" let {src,options}=args\n const lines = src.split(/\\r?\\n|\\r\\n?/);\n let lino = -1;\n let currentOffset = 0;\n \n while (++lino < lines.length) {\n let pa=null;\n let line = lines[lino];\n\n // MD remove `\\label`, do not change number of lines, directly replace\n line=line\n .replace(/\\\\label{.*?}/g,'')\n .replace(/\\\\chapter{(.*?)}/g,'# $1')\n .replace(/\\\\section{(.*?)}/g,'## $1')\n .replace(/\\\\subsection{(.*?)}/g,'### $1')\n .replace(/\\\\subsubsection{(.*?)}/g,'#### $1')\n .replace(/\\\\paragraph{(.*?)}/g,'##### $1')\n .replace(/\\\\subparagraph{(.*?)}/g,'##### $1')\n\n // MD fix equation, add 3 more lines. fix offset for trace\n pa=/\\\\begin{(equation|display|alignat|aligned|align|multline|flalign)}/\n if (pa.exec(line)){\n line=line.replace(pa,(m)=>'\\n\\n$$\\n'+m)\n currentOffset+=3\n options.offset.push([lino + currentOffset, currentOffset])\n }\n\n // MD fix equation\n pa=/\\\\end{(equation|display|alignat|aligned|align|multline|flalign)}/\n if (pa.exec(line)){\n line=line.replace(pa,(m)=>m+'\\n$$\\n\\n')\n currentOffset+=3\n options.offset.push([lino + currentOffset, currentOffset])\n }\n\n lines[lino] = line;\n }\n return lines.join('\\r\\n');\n \n "}
    ],

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.