Giter Club home page Giter Club logo

showdown-highlight's Introduction

showdown-highlight

Version Downloads

A Showdown extension for highlight the code blocks.

This package uses highlight.js to highlight code blocks in Showdown output. ๐Ÿš€

โ˜๏ธ Installation

# Using npm
npm install --save showdown-highlight

# Using yarn
yarn add showdown-highlight

๐Ÿ“‹ Example

const showdown = require('showdown')
    , showdownHighlight = require("showdown-highlight")
    ;

// After requiring the module, use it as extension
let converter = new showdown.Converter({
    // That's it
    extensions: [showdownHighlight({
        // Whether to add the classes to the <pre> tag, default is false
        pre: true
        // Whether to use hljs' auto language detection, default is true
    ,   auto_detection: true
    })]
});

// Now you can Highlight code blocks
let html = converter.makeHtml(`
## Highlighting Code with Showdown

Below we have a piece of JavaScript code:

\`\`\`js
function sayHello (msg, who) {
    return \`\${who} says: msg\`;
}
sayHello("Hello World", "Johnny");
\`\`\`
`);

console.log(html);
// <h2 id="highlightingcodewithshowdown">Highlighting Code with Showdown</h2>
//
// <p>Below we have a piece of JavaScript code:</p>
//
// <pre><code class="js language-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sayHello</span> (<span class="hljs-params">msg, who</span>) </span>{
//     <span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${who}</span> says: msg`</span>;
// }
// sayHello(<span class="hljs-string">"Hello World"</span>, <span class="hljs-string">"Johnny"</span>);
// </code></pre>

โ“ Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. ๐Ÿ›

๐Ÿ“ Documentation

showdownHighlight()

Highlight the code in the showdown input.

Examples:

let converter = new showdown.Converter({
    extensions: [showdownHighlight]
})

Enable the classes in the <pre> element:

let converter = new showdown.Converter({
    extensions: [showdownHighlight({ pre: true })]
})

If you want to disable language auto detection feature of hljs, change auto_detection flag as false. With this option turned off, showdown-highlight will not process any codeblocks with no language specified.

let converter = new showdown.Converter({
    extensions: [showdownHighlight({ auto_detection: false })]
})

๐Ÿ˜‹ How to contribute

Have an idea? Found a bug? See how to contribute.

๐Ÿ’ซ Where is this library used?

If you are using this library in one of your projects, add it in this list. โœจ

  • mdpdf
  • bloggify-markdown-highlight
  • github-readme-to-html
  • md-toy-blog
  • @kev_nz/publisher
  • @etermind/alex
  • @siradoc/siradoc
  • @web-native-js/chtml-cli
  • swanky
  • md-srv
  • docset-tools-markdown
  • callete
  • teroshdl2
  • ui_kitchenadmincenter
  • trumpdoc
  • @peersky/next-web3-chakra
  • mdpdf_jm
  • textbase
  • teroshdl
  • showdown-html
  • busi-ui
  • md-browse
  • markdown2dash
  • tutors-reader-lib
  • tutors-html-beta
  • tutors-html
  • examma-ray
  • steelsky
  • chimpsky
  • ember-showdown-highlight
  • showit
  • tutors-html-alpha

๐Ÿ“œ License

MIT ยฉ Bloggify

showdown-highlight's People

Contributors

dependabot[bot] avatar devbaraus avatar expedit85 avatar ionicabizau avatar isidoraslavkovic avatar mikakruschel avatar obedm503 avatar phryxia avatar robbiethewagner avatar webdevelopland avatar yuimai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

showdown-highlight's Issues

Highlight those code blocks only with a class?

Hi,

I've got a 2 code blocks:

~~~
define foobar() {
    print "Welcome to flavor country!";
}
~~~

~~~python
import time
# Quick, count to ten!
for i in range(10):
    # (but not *too* quick)
    time.sleep(0.5)
    print(i)
~~~

However, they are being rendered as:

screen shot 2018-09-22 at 13 13 22

Notice the unnecessary hljs string at the beginning of the first code block, looks like a bug?

Here's the HTML:

screen shot 2018-09-22 at 13 16 10

Should the library just ignore code blocks that don't have a class defined?

Unable to load style

I am using it in vuejs

My Snippet

// imports
import showdown from "showdown";
import sh from "showdown-highlight";
import "highlight.js/styles/agate.css";

// creating the converter
let c = new showdown.Converter({ extensions: [sh] });
document.querySelector('#preview') = c.makeHtml(this.content);

My Output

image

Expected

Should load style like this

image

Language name support

Hi,

the language name in the markdown is not used at all:

```js
code goes here
```

and I see in the output:

<pre><code class="something-else ...">...

Regards.

Add language to pre tag

I need to customize the pre tag based on which language is within it. So could you add an option where we can select rather or not we want this additional class?

```js
console.log('hello')
```

<pre class="language-js">...<pre>

Thanks! ๐Ÿ’œ

Inline code doesn't appear to be highlighted

Code blocks with the following format:

console.log('hi');

are highlighted correctly, because the hljs classes are added as expected. However inline code such as:

This is a line of text which contains inline code of console.log('hi'); within it.

doesn't seem to have the hljs classes added, so no highlighting occurs.

Am I doing something wrong, or does showdown-highlight / highlightjs not support inline code?

Thanks.

Is there anyway to inline css classes?

First of all thanks for building a great highlight.js integration.

I am wondering is there anyway to make the styles inline?

What I want is instead of <element class="js language-js"> to have this <element style="....">

Add an option to disable auto language detection

Before the discussion, I'd like to thank for this great library! The proposal is very simple. Can we add an option to disable the language auto detection?

The usage for this is to express some errors or terminal related things with code fences. For example, if I render a block of code with language unspecified, then it looks like:

image

One can be modified like this. This won't break current behavior. If language is not specified with no auto detection, there is no reason to pass this extension. That's the reason I edited the left regexp. Since I misunderstood something, I deleted previous posted code.

I'd like to listen your feedback before I do that.

(+ I'm work in progress for this)

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.