GithubHelp home page GithubHelp logo

doc22940 / my-highlighter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from matejlednar/my-highlighter

0.0 1.0 0.0 45 KB

Syntax Highlighter for JS, HTML, XML and DOM

CSS 10.00% JavaScript 45.71% HTML 44.29%

my-highlighter's Introduction

My-highlighter

Syntax Highlighter for JS, HTML, XML and DOM. My highlighter

For version history see history documentation.

(c) 2012-2014 Author: PhDr. Matej Lednár, PhD.

JavaScript simple syntax highlighter with support XML, HTML, Javascript, and DOM languages. This library supports only latest web browsers. User can use universal highlighter with class code, or special highlighters for HTML and JavaScript

My highlighter features:

  • user can use own library prefix,
  • user can use own class name prefix,
  • user can run library manually or automatic,
  • user can define colors and statements for HTML, XML, JavaScript and DOM,
  • user can use own CSS rules,
  • user can display and highlight website's source code (must be a descendant of the element),
  • user can display and highlight inserted content into <textarea> element,
  • user can define the content that may displays only once, add data-code="once" to the target element,
  • inserted code is valid html document

TODO:

  • add JS/DOM support - more statements,
  • new option - change display order: output source <--> source output,
  • highlight defined lines, e.g. data-highlight="2,5,6-8,11",
  • display plain text,

Prohibited string:

  • ^^|^ - semicolon replacer

Use HTML script element for library activation.

<script [data-code="false|true"] [data-class="className"] [data-indent="true"]
[data-conflict="libraryPrefix"] [data-highlight-only="false|true"] src="my-highlighter.js"></script>

User can invoke _.showCode() method unlimited times and defines elements that will be highlighted only once.

<element data-code="once"> content </element>

Default library settings.

 <link rel="StyleSheet" type="text/css" href="default.css"/>
 <script src="my-highlighter.js"></script>

Recommended settings for JavaScript frameworks (e.g. Dojo).

Run showCode(); manually. showCode() method will be deleted from the output.

 <script src="my-highlighter.js" data-code="false"></script>
 _.showCode();  // see demos

HTML attributes description:

  • data-code="false" - disables automatic highlighting, user can run the highlighter manually.
  • data-class="className" - changes highlighter's class name.
  • data-conflict="prefix" - changes library's prefix.
  • data-highlight-only="true" - highlights only elements with class="code", no node clone.
  • data-indent="true" - allows left indentation of the content

Library's functions overview

This is a part of the mllibrary.js (author: Matej Lednár)

The library prefix is _ (underscore).

Method name Method description

  • _.tag(element, index) gets an element from nodelist by index
  • _.log(data) writes an argument into console
  • _.regEvent(element, event, function, phase) registers an event listener
  • _.showCode() if the script element contains data-code="true", displays content of all elements with class="code"
  • _.initLibrary() allows change the library prefix via data-conflict attribute and enable / disable invoke _.showCode() automatically.
  • _.runLibrary() runs showCode() and defines prefix of the library

Web sites:

  • work.mldgroup.com
  • how-to.mldgroup.com

my-highlighter's People

Contributors

matejlednar avatar

Watchers

 avatar

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.