Coder Social home page Coder Social logo

changhuixu / ngx-highlightjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from murhafsousli/ngx-highlightjs

0.0 3.0 0.0 2.41 MB

Angular syntax highlighting module

Home Page: https://murhafsousli.github.io/ngx-highlightjs/

License: MIT License

JavaScript 1.96% TypeScript 15.29% HTML 6.20% CSS 76.54%

ngx-highlightjs's Introduction

Angular Highlight.js

npm npm npm Build Status npm npm npm bundle size (minified + gzip) npm

Instant code highlighting, auto-detect language, super easy to use


Table of Contents

NPM

$ npm install -S ngx-highlightjs highlight.js

YARN

$ yarn add ngx-highlightjs highlight.js

Import HighlightModule library from any module:

import { HighlightModule } from 'ngx-highlightjs';

import xml from 'highlight.js/lib/languages/xml';
import scss from 'highlight.js/lib/languages/scss';
import typescript from 'highlight.js/lib/languages/typescript';

/**
 * Import every language you wish to highlight here
 * NOTE: The name of each language must match the file name its imported from
 */
export function hljsLanguages() {
  return [
    {name: 'typescript', func: typescript},
    {name: 'scss', func: scss},
    {name: 'xml', func: xml}
  ];
}

@NgModule({
  imports: [
    // ...
    HighlightModule.forRoot({
      languages: hljsLanguages
    })
  ]
})
export class AppModule { }

HighlightModule.forRoot(options) Should be called at least once to register highlighting languages.

forRoot(options) Accepts options parameter which have the following properties:

  • languages: The set of languages to register.
  • config: Configures global options, see configure-options.

Import highlighting theme

@import '~highlight.js/styles/github.css';

List of all available themes from highlight.js

highlight directive

Highlight host element

<pre><code [highlight]="someCode"></code></pre>

Check this stackblitz

Options

  • [highlight]: (string), Accept code string to highlight, default null

  • [language]: (string[]), an array of language names and aliases restricting auto detection to only these languages, default: null

  • (highlighted): Stream that emits HighlightResult object when element is highlighted.

highlightChildren directive

Highlight children code elements

<!-- Highlight child elements with 'pre code' selector -->
<div highlightChildren>
  <pre><code [textContent]="htmlCode"></code></pre>
  <pre><code [textContent]="tsCode"></code></pre>
  <pre><code [textContent]="cssCode"></code></pre>
</div>

Check this stackblitz

  • Highlight children custom elements by selector
<!-- Highlight child elements with custom selector -->
<div highlightChildren="section p">
  <section><p [textContent]="pythonCode"></p></section>
  <section><p [textContent]="swiftCode"></p></section>
</div>

HighlightJS service

Use this service if you wish to access the Official HighlightJS API.

This project uses Angular CLI to build the package.

$ ng build ngx-highlightjs --prod

If you identify any errors in the library, or have an idea for an improvement, please open an issue.

Murhaf Sousli

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.