GithubHelp home page GithubHelp logo

durlecode / editorjs-simple-html-parser Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 10.0 71 KB

A simple html parser write in php for Editor.js

License: GNU General Public License v3.0

PHP 100.00%
editorjs html5 php7

editorjs-simple-html-parser's Introduction

codecov License: GPL v3

Simple PHP Parser for Editor.js

Parse to HTML clean JSON Data from Editor.js

Installation

composer require durlecode/editorjs-simple-html-parser

Usage

use Durlecode\EJSParser\Parser;

$html = Parser::parse($data)->toHtml();

Where $data is the clean JSON data coming from Editor.js See $data example below

{
    "time" : 1583848289745,
    "blocks" : [
        {
            "type" : "header",
            "data" : {
                "text" : "Hello World",
                "level" : 2
            }
        }
    ],
    "version" : "2.16.1"
}

By default this will generate html with css classes with prs prefix, so if you want to change it, follow example below

use Durlecode\EJSParser\Parser;

$parser = new Parser($data);

$parser->setPrefix("cat");

$parsed = $parser->toHtml();

Supported Tools

Package Key Main CSS Class
@editorjs/code code .prs-code
@editorjs/embed embed .prs-embed
@editorjs/delimiter delimiter .prs-delimiter
@editorjs/header header .prs-h{header-level}
@editorjs/inline-code
@editorjs/link link .prs-link
@editorjs/list list .prs-list
@editorjs/marker
@editorjs/paragraph paragraph .prs-paragraph
@editorjs/raw raw
@editorjs/simple-image simpleImage .prs-image
@editorjs/warning warning .prs-warning

Methods

toHtml()

Return generated HTML

setPrefix(string $prefix)

Set CSS classes Prefix

getPrefix()

Return current prefix

getVersion()

Return Editor.js content version

getTime()

Return Editor.js content timestamp

getBlocks()

Return Editor.js content blocks

Generated HTML

Code
<div class="prs-code">
    <pre>
        <code></code>
    </pre>
</div>
Embed
(Actually working with Youtube, Codepen & Gfycat)
<div class="prs-embed">
    <iframe src="" height="300"></iframe>
</div>
Delimiter
<hr class="prs-delimiter">
Header
<h2 class="prs-h2">Lorem</h2>
Link
<a href="https://github.com/" target="_blank" class="prs-link">
    <div class="prs-link-container-with-img">
        <div class="prs-link-title">Title</div>
        <div class="prs-link-description">Description</div>
        <div class="prs-link-url">https://example.com/</div>
    </div>
    <div class="prs-link-img-container">
        <img src="https://example.com/cat.png" alt="">
    </div>
</a>
Ordered List
<div class="prs-list">
    <ol>
        <li></li>
    </ol>
</div>
Unordered List
<div class="prs-list">
    <ul>
        <li></li>
    </ul>
</div>
Paragraph
<p class="prs-paragraph">
    <code class="inline-code">Pellentesque</code> 
    <i>malesuada fames</i> 
    <mark class="cdx-marker">tempus</mark>
</p>
Image
<figure class="prs-image">
    <img src="" class="prs-image-border prs-image-background" alt="">
    <figcaption></figcaption>
</figure>
Warning
<div class="prs-warning">
    <ion-icon name="information-outline" size="large" aria-label="information outline"></ion-icon>
    <div>
        <p>Title</p>
        <p>Message</p>
    </div>
</div>
Raw
<div class="prs-raw">
    Raw HTML ...
</div>

editorjs-simple-html-parser's People

Contributors

durlecode avatar mecodebot avatar smosmochatton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

editorjs-simple-html-parser's Issues

Header blocks render non-breaking space entities

Header blocks are rendering encoded &nbsp;. Reviewing the code shows it's written differently from how a Paragraph block is handled, for example.

I tried to fix this by subclassing the library and providing my own parseHeader() method, but with everything having a private visibility, this didn't work.

Are you open to pull-requests to fix these issues?

  1. Change visibility from private to protected so that the library can be subclassed.
  2. Fix the parseHeader() method.

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.