├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .php_cs ├── .styleci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── bin └── coverage ├── composer.json ├── examples └── jigsaw │ ├── .gitignore │ ├── Parser.php │ ├── README.md │ ├── bootstrap.php │ ├── composer.json │ ├── config.php │ ├── package.json │ ├── source │ ├── _assets │ │ ├── js │ │ │ └── main.js │ │ └── sass │ │ │ └── main.scss │ ├── _layouts │ │ └── master.blade.php │ ├── assets │ │ └── images │ │ │ └── jigsaw.png │ ├── index.blade.php │ └── test-post.md │ ├── tasks │ ├── bin.js │ └── build.js │ ├── webpack.mix.js │ └── yarn.lock └── src ├── ParsedownHighlight.php └── ParsedownHighlightExtra.php /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## What are the steps to reproduce this issue? 4 | 5 | 1. … 6 | 2. … 7 | 3. … 8 | 9 | ## What happens? 10 | … 11 | 12 | ## What were you expecting to happen? 13 | … 14 | 15 | ## Any logs, error output, etc? 16 | … 17 | 18 | ## Any other comments? 19 | … 20 | 21 | ## What versions are you using? 22 | **Operating System:** … 23 | **Package Version:** … 24 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Status 2 | 3 | **READY/WIP/HOLD** 4 | 5 | ## Description 6 | A few sentences describing the overall goals of the pull request's commits. 7 | 8 | ## Related PRs 9 | List related PRs against other branches: 10 | 11 | branch | PR 12 | ------ | ------ 13 | other_pr_production | [link]() 14 | other_pr_master | [link]() 15 | 16 | ## Todos 17 | - [ ] Tests 18 | - [ ] Documentation 19 | - [ ] Changelog Entry (unreleased) 20 | 21 | ## Steps to Test or Reproduce 22 | Outline the steps to test or reproduce the PR here. 23 | 24 | ```bash 25 | > git pull --prune 26 | > git checkout 27 | > vendor/bin/phpunit 28 | ``` 29 | 30 | 1. 31 | -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | true, 5 | 'array_syntax' => ['syntax' => 'short'], 6 | 'no_multiline_whitespace_before_semicolons' => true, 7 | 'no_short_echo_tag' => true, 8 | 'no_unused_imports' => true, 9 | 'not_operator_with_successor_space' => true, 10 | 'no_useless_else' => true, 11 | 'ordered_imports' => [ 12 | 'sortAlgorithm' => 'length', 13 | ], 14 | 'phpdoc_add_missing_param_annotation' => true, 15 | 'phpdoc_indent' => true, 16 | 'phpdoc_no_package' => true, 17 | 'phpdoc_order' => true, 18 | 'phpdoc_separation' => true, 19 | 'phpdoc_single_line_var_spacing' => true, 20 | 'phpdoc_trim' => true, 21 | 'phpdoc_var_without_name' => true, 22 | 'phpdoc_to_comment' => true, 23 | 'single_quote' => true, 24 | 'ternary_operator_spaces' => true, 25 | 'trailing_comma_in_multiline_array' => true, 26 | 'trim_array_spaces' => true, 27 | ]; 28 | 29 | $excludes = [ 30 | 'vendor', 31 | 'storage', 32 | 'node_modules', 33 | 'bootstrap/cache', 34 | ]; 35 | 36 | return PhpCsFixer\Config::create() 37 | ->setRules($rules) 38 | ->setFinder( 39 | PhpCsFixer\Finder::create() 40 | ->in(__DIR__) 41 | ->exclude($excludes) 42 | ->notName('README.md') 43 | ->notName('*.xml') 44 | ->notName('*.yml') 45 | ->notName('_ide_helper.php') 46 | ); -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - single_class_element_per_statement 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 5 | 6 | ## [Unreleased] 7 | 8 | ## [0.4.0] - 2020-05-20 9 | ### Added 10 | * Support for ParsedownExtra - [#10](https://github.com/sixlive/parsedown-highlight/pull/10) 11 | 12 | ## [0.3.0] - 2019-02-08 13 | ### Changed 14 | * Highlight php version was changed to be less restricitve ([#4](https://github.com/sixlive/parsedown-highlight/pull/4)) 15 | 16 | ## [0.2.0] - 2018-11-08 17 | ### Changed 18 | * Updated parsedown to `beta-5` ([#2](https://github.com/sixlive/parsedown-highlight/pull/2)) 19 | 20 | ### Added 21 | * Jigsaw example ([#1](https://github.com/sixlive/parsedown-highlight/pull/1)) 22 | 23 | ## [0.1.0] - 2018-11-06 24 | Initial release 25 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - We have provided [tooling](README.md#code-style) to make this as easy as possible. 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) TJ Miller 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Parsedown Highlight 2 | 3 | ## *NOTE: This requires v1.8 of Parsedown, which has not been released yet.* 4 | 5 | [![Packagist Version](https://img.shields.io/packagist/v/sixlive/parsedown-highlight.svg?style=flat-square)](https://packagist.org/packages/sixlive/parsedown-highlight) 6 | [![Packagist Downloads](https://img.shields.io/packagist/dt/sixlive/parsedown-highlight.svg?style=flat-square)](https://packagist.org/packages/sixlive/parsedown-highlight) 7 | [![Travis](https://img.shields.io/travis/sixlive/parsedown-highlight.svg?style=flat-square)](https://travis-ci.org/sixlive/parsedown-highlight) 8 | [![Code Quality](https://img.shields.io/scrutinizer/g/sixlive/parsedown-highlight.svg?style=flat-square)](https://scrutinizer-ci.com/g/sixlive/parsedown-highlight/) 9 | [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/sixlive/parsedown-highlight.svg?style=flat-square)](https://scrutinizer-ci.com/g/sixlive/parsedown-highlight/) 10 | [![StyleCI](https://github.styleci.io/repos/156398051/shield)](https://github.styleci.io/repos/156398051) 11 | 12 | This extends Parsedown to add support for server side code block rendering. This uses [scrivo/highlight.php](https://github.com/scrivo/highlight.php) to do all the code block rendering. This will be fully compatible with Highlight JS. 13 | 14 | ## Installation 15 | You can install the package via composer: 16 | 17 | ```bash 18 | > composer require sixlive/parsedown-highlight 19 | ``` 20 | 21 | ## Usage 22 | 23 | ```md 24 | # Hello! 25 | 26 | Here is a post with some code in it. 27 | 28 | \```php 29 | text(file_get_contents(__DIR__.'/README.md')); 43 | ``` 44 | 45 | ```html 46 |

Hello!

47 |

Here is a post with some code in it.

48 |
<?php
 49 | 
 50 | echo 'foo';
51 |
put 'WHOOP!'
52 | ``` 53 | 54 | ### Using Parsedown Extra 55 | **Note: This requires version [0.8.0-beta-1](https://github.com/erusev/parsedown-extra/releases/tag/0.8.0-beta-1)** 56 | 57 | ```php 58 | $parsedown = new \sixlive\ParsedownHighlightExtra; 59 | 60 | $parsedown->text(file_get_contents(__DIR__.'/README.md')); 61 | ``` 62 | 63 | 64 | ## Testing 65 | 66 | ``` bash 67 | > composer test 68 | ``` 69 | 70 | ## Changelog 71 | 72 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 73 | 74 | ## Contributing 75 | 76 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 77 | 78 | ## Code Style 79 | In addition to the php-cs-fixer rules, StyleCI will apply the [Laravel preset](https://docs.styleci.io/presets#laravel). 80 | 81 | ### Linting 82 | ```bash 83 | > composer styles:lint 84 | ``` 85 | 86 | ### Fixing 87 | ```bash 88 | > composer styles:fix 89 | ``` 90 | 91 | ## Security 92 | 93 | If you discover any security related issues, please email oss@tjmiller.co instead of using the issue tracker. 94 | 95 | ## Credits 96 | 97 | - [TJ Miller](https://github.com/sixlive) 98 | - [All Contributors](../../contributors) 99 | 100 | ## License 101 | 102 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 103 | -------------------------------------------------------------------------------- /bin/coverage: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $1 = 'report' ]]; then 4 | wget https://scrutinizer-ci.com/ocular.phar 5 | php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml 6 | fi 7 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sixlive/parsedown-highlight", 3 | "description": "Server side code block rendering for Parsedown", 4 | "keywords": [ 5 | "markdown", 6 | "code", 7 | "parsedown" 8 | ], 9 | "homepage": "https://github.com/sixlive/parsedown-highlight", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "TJ Miller", 14 | "email": "oss@tjmiller.co", 15 | "homepage": "https://tjmiller.co", 16 | "role": "Developer" 17 | } 18 | ], 19 | "require": { 20 | "php": "^7.1|7.2", 21 | "erusev/parsedown": "1.8.0-beta-5", 22 | "scrivo/highlight.php": "^9.14", 23 | "erusev/parsedown-extra": "0.8.0-beta-1" 24 | }, 25 | "require-dev": { 26 | "friendsofphp/php-cs-fixer": "^2.10", 27 | "larapack/dd": "^1.0", 28 | "sempro/phpunit-pretty-print": "^1.0", 29 | "phpunit/phpunit": "^6.0|^7.0" 30 | }, 31 | "autoload": { 32 | "psr-4": { 33 | "sixlive\\": "src" 34 | } 35 | }, 36 | "autoload-dev": { 37 | "psr-4": { 38 | "Tests\\": "tests" 39 | } 40 | }, 41 | "scripts": { 42 | "test": "phpunit", 43 | "styles:lint": "php-cs-fixer fix --dry-run --diff", 44 | "styles:fix": "php-cs-fixer fix" 45 | }, 46 | "config": { 47 | "sort-packages": true 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/jigsaw/.gitignore: -------------------------------------------------------------------------------- 1 | /build_local/ 2 | /node_modules/ 3 | /vendor/ 4 | -------------------------------------------------------------------------------- /examples/jigsaw/Parser.php: -------------------------------------------------------------------------------- 1 | composer install 6 | > jigsaw build 7 | > jigsaw serve 8 | ``` 9 | 10 | After setup, pop open a browser and visit the URL that jigsaw is served at `/test-post`. 11 | 12 | ## Walkthrough 13 | 14 | To add Parsedown highlight there are a few manual steps (for now) that need to be done to get it configured. 15 | 16 | ### 1) Add the library 17 | 18 | ```bash 19 | > composer require sixlive/parsedown-highlight 20 | ``` 21 | 22 | ### 2) Create Parser.php 23 | Jigsaw binds the markdown parser using the `Mni\FrontYAML\Markdown\MarkdownParser` contract. Parsedown does have the methods to satisfy the contract but does not physically implement it so we need to create a class that implements the contract. 24 | 25 | ```php 26 | bind(MarkdownParser::class, Parser::class); 52 | ``` 53 | -------------------------------------------------------------------------------- /examples/jigsaw/bootstrap.php: -------------------------------------------------------------------------------- 1 | bind(MarkdownParser::class, Parser::class); 13 | 14 | /* 15 | * You can run custom code at different stages of the build process by 16 | * listening to the 'beforeBuild', 'afterCollections', and 'afterBuild' events. 17 | * 18 | * For example: 19 | * 20 | * $events->beforeBuild(function (Jigsaw $jigsaw) { 21 | * // Your code here 22 | * }); 23 | */ 24 | -------------------------------------------------------------------------------- /examples/jigsaw/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sixlive/jigsaw-example", 3 | "type": "project", 4 | "minimum-stability": "dev", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "TJ Miller", 9 | "email": "oss@tjmiller.co" 10 | } 11 | ], 12 | "require": { 13 | "sixlive/parsedown-highlight": "^0.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/jigsaw/config.php: -------------------------------------------------------------------------------- 1 | '', 5 | 'production' => false, 6 | 'collections' => [], 7 | ]; 8 | -------------------------------------------------------------------------------- /examples/jigsaw/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "local": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --env=local --config=node_modules/laravel-mix/setup/webpack.config.js", 5 | "staging": "cross-env NODE_ENV=staging node_modules/webpack/bin/webpack.js --progress --hide-modules --env=staging --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --env=production --config=node_modules/laravel-mix/setup/webpack.config.js", 7 | "dev": "npm run local", 8 | "watch": "npm run local -- --watch" 9 | }, 10 | "devDependencies": { 11 | "browser-sync": "^2.23.6", 12 | "browser-sync-webpack-plugin": "^2.0.1", 13 | "cross-env": "^3.2.3", 14 | "hasbin": "^1.2.3", 15 | "laravel-mix": "^2.0.0", 16 | "node-cmd": "^3.0.0", 17 | "on-build-webpack": "^0.1.0", 18 | "webpack-watch": "^0.2.0", 19 | "yargs": "^4.6.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/jigsaw/source/_assets/js/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixlive/parsedown-highlight/21301536bee43a7249a48933f030cbac3a9d2402/examples/jigsaw/source/_assets/js/main.js -------------------------------------------------------------------------------- /examples/jigsaw/source/_assets/sass/main.scss: -------------------------------------------------------------------------------- 1 | .hljs{display:block;overflow-x:auto;padding:.5em;color:#abb2bf;background:#282c34}.hljs-comment,.hljs-quote{color:#5c6370;font-style:italic}.hljs-doctag,.hljs-formula,.hljs-keyword{color:#c678dd}.hljs-deletion,.hljs-name,.hljs-section,.hljs-selector-tag,.hljs-subst{color:#e06c75}.hljs-literal{color:#56b6c2}.hljs-addition,.hljs-attribute,.hljs-meta-string,.hljs-regexp,.hljs-string{color:#98c379}.hljs-built_in,.hljs-class .hljs-title{color:#e6c07b}.hljs-attr,.hljs-number,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-pseudo,.hljs-template-variable,.hljs-type,.hljs-variable{color:#d19a66}.hljs-bullet,.hljs-link,.hljs-meta,.hljs-selector-id,.hljs-symbol,.hljs-title{color:#61aeee}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}.hljs-link{text-decoration:underline} -------------------------------------------------------------------------------- /examples/jigsaw/source/_layouts/master.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | @yield('body') 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/jigsaw/source/assets/images/jigsaw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sixlive/parsedown-highlight/21301536bee43a7249a48933f030cbac3a9d2402/examples/jigsaw/source/assets/images/jigsaw.png -------------------------------------------------------------------------------- /examples/jigsaw/source/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('_layouts.master') 2 | 3 | @section('body') 4 |

Hello world!

5 | @endsection 6 | -------------------------------------------------------------------------------- /examples/jigsaw/source/test-post.md: -------------------------------------------------------------------------------- 1 | --- 2 | extends: _layouts/master 3 | section: body 4 | --- 5 | 6 | ```php 7 | { 16 | command.get(bin.path() + ' build ' + env, (error, stdout, stderr) => { 17 | console.log(error ? stderr : stdout); 18 | 19 | if (browserSyncInstance) { 20 | browserSyncInstance.reload(); 21 | } 22 | }); 23 | }), 24 | 25 | watch: function(paths) { 26 | return new Watch({ 27 | options: { ignoreInitial: true }, 28 | paths: paths, 29 | }) 30 | }, 31 | 32 | browserSync: function(proxy) { 33 | return new BrowserSyncPlugin({ 34 | notify: false, 35 | port: port, 36 | proxy: proxy, 37 | server: proxy ? null : { baseDir: 'build_' + env + '/' }, 38 | }, 39 | { 40 | reload: false, 41 | callback: function() { 42 | browserSyncInstance = BrowserSync.get('bs-webpack-plugin'); 43 | }, 44 | }) 45 | }, 46 | }; 47 | -------------------------------------------------------------------------------- /examples/jigsaw/webpack.mix.js: -------------------------------------------------------------------------------- 1 | let mix = require('laravel-mix'); 2 | let build = require('./tasks/build.js'); 3 | 4 | mix.disableSuccessNotifications(); 5 | mix.setPublicPath('source/assets/build'); 6 | mix.webpackConfig({ 7 | plugins: [ 8 | build.jigsaw, 9 | build.browserSync(), 10 | build.watch(['source/**/*.md', 'source/**/*.php', 'source/**/*.scss', '!source/**/_tmp/*']), 11 | ] 12 | }); 13 | 14 | mix.js('source/_assets/js/main.js', 'js') 15 | .sass('source/_assets/sass/main.scss', 'css') 16 | .options({ 17 | processCssUrls: false, 18 | }).version(); 19 | -------------------------------------------------------------------------------- /src/ParsedownHighlight.php: -------------------------------------------------------------------------------- 1 | highlighter = new Highlighter; 16 | } 17 | 18 | protected function blockFencedCodeComplete($block) 19 | { 20 | if (! isset($block['element']['element']['attributes'])) { 21 | return $block; 22 | } 23 | 24 | $code = $block['element']['element']['text']; 25 | $languageClass = $block['element']['element']['attributes']['class']; 26 | $language = explode('-', $languageClass); 27 | 28 | try { 29 | $highlighted = $this->highlighter->highlight($language[1], $code); 30 | $block['element']['element']['attributes']['class'] = vsprintf('%s hljs %s', [ 31 | $languageClass, 32 | $highlighted->language, 33 | ]); 34 | $block['element']['element']['rawHtml'] = $highlighted->value; 35 | unset($block['element']['element']['text']); 36 | } catch (DomainException $e) { 37 | // 38 | } 39 | 40 | return $block; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/ParsedownHighlightExtra.php: -------------------------------------------------------------------------------- 1 | highlighter = new Highlighter; 16 | } 17 | 18 | protected function blockFencedCodeComplete($block) 19 | { 20 | if (! isset($block['element']['element']['attributes'])) { 21 | return $block; 22 | } 23 | 24 | $code = $block['element']['element']['text']; 25 | $languageClass = $block['element']['element']['attributes']['class']; 26 | $language = explode('-', $languageClass); 27 | 28 | try { 29 | $highlighted = $this->highlighter->highlight($language[1], $code); 30 | $block['element']['element']['attributes']['class'] = vsprintf('%s hljs %s', [ 31 | $languageClass, 32 | $highlighted->language, 33 | ]); 34 | $block['element']['element']['rawHtml'] = $highlighted->value; 35 | unset($block['element']['element']['text']); 36 | } catch (DomainException $e) { 37 | // 38 | } 39 | 40 | return $block; 41 | } 42 | } 43 | --------------------------------------------------------------------------------