Code Monkey home page Code Monkey logo

markdown-to-englighter-wordpress's Introduction

Markdown to Englighter WordPress Script

This script will render a Markdown file to HTML, injecting special HTML attributes for the Englighter WordPress code plugin.

Installation

You'll need the Node.js runtime installed on your machine. With Node in place, just run the following from the command line, in the project root directory.

npm install

Usage

  1. Add a Markdown file exported from Ulysses to the {project_root}/docs directory. Make sure to name the file in.md.
  2. Run npm start

This should generate a file called {project_root}/docs/out.html, the contents of which you can copy and paste into a WordPress post.

Code Blocks

This script will not work with indented code blocks. Please mark code blocks with ``` instead.

    This will not
    work.
```
This will work
fine
```

Enlighter Sugar

This script assumes that you're using the Enlighter WordPress plugin for code highlighting.

You can add the following sugar to your Markdown for automatic conversion to Enlighter data attributes in the generated HTML.

File Name as Title

@file:src/foo/bar.js
const thing = require("foobar");

// ...

The @file:your_file_name will get converted to a data-enlighter-title attribute so that the file path will show as the title of the code block. So the above will be rendered as follows.

<pre
  class="EnlighterJSRAW"
  data-enlighter-language="generic"
  data-enlighter-linenumbers="false"
  data-enlighter-group="a4396d38-4fe5-4b14-9d35-f0a2a57a7be0"
  <!--
  GUID
  --
>
  data-enlighter-title="src/foo/bar.js"
>
const thing = require("foobar");

// ...
</pre>

Line Highlights

In a code block, each line marked with ** will be added to the data-enlighter-highlight list attribute so that the line will be higlighted when rendered.

let oldCode = lookNormal();

**let newCode = beHighlighted();
**newCode.forEach(line => {
**  line.standOut();
**});

The above code will render to the following.

<pre class="EnlighterJSRAW"
  data-enlighter-language="generic"
  data-enlighter-linenumbers="false"
   data-enlighter-highlight="3,4,5,6"
>
let oldCode = lookNormal();

let newCode = beHighlighted();
newCode.forEach(line => {
  line.standOut();
});
</pre>

βœ‹πŸ½ Heads up Each ** will be replaced with an empty string, so make sure that your code indentation acts as if the **s don't exist at all.

Images

<img> tags will be replaced with a highlight placeholder to make adding images in your final WordPress post easier.

<img src="foo.png" alt="Picture of a foo">

...will render to...

<div><strong style="color: #ff6600;">πŸ“Έ foo.png (Picture of a foo)</strong></div>

βœ‹πŸ½ Heads up An alt tag will not be rendered in the placeholder if its value is exactly the same as the src e.g. <img src="bar.png" alt="bar.png"> will render to <div><strong style="color: #ff6600;">πŸ“Έ bar.png</strong></div>.

Development and testing

This script is unit-tested with Jest. To run all tests:

npm run test

To run Jest in watch mode:

npm run dev

-- Happy coding πŸ₯ΈπŸ€“

markdown-to-englighter-wordpress's People

Contributors

ashour 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.