Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Jun 21, 2019
2 parents ae8ffb9 + 4394acf commit 7bfff69
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v1.0.1
## 06/20/2019

1. [](#improved)
* Moved away from jQuery syntax and converted to VanillaJS
* Fixed typos
* Added extra syntax highlighting format

# v1.0.0
## 04/16/2019

Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,31 @@ Prism.js supports currently [176 languages](http://prismjs.com/#languages-list),
* mathml
* css
* css-extras
* c-lik
* clike
* javascript, js
* apache
* bash
* sh
* coffee
* apacheconf
* bash, shell
* coffeescript, coffee
* diff
* docker
* docker, dockerfile
* git
* go
* java
* json
* json5
* less
* lua
* markdown
* markdown, md
* php
* php-extras
* python
* python, py
* regex
* ruby
* ruby, rb
* sass
* scss
* sql
* twig
* yaml
* yaml, yml

# Plugins Included

Expand All @@ -73,7 +72,9 @@ This build of Prism also includes the following plugins:

# Basic Usage

In your markdown, you can create a block of code, and assign the language to it. You can choose between the list above. Example:
In your markdown, you can create a block of code, and assign the language to it. You can choose between the list above.

Example using regular markdown fenced code syntax:

```php
```php
Expand All @@ -99,7 +100,6 @@ In your markdown, you can create a block of code, and assign the language to it.
];
}
}
```
```

# Advanced Usage
Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Prism Highlighter
version: 1.0.0
version: 1.0.1
description: "This plugin provides code highlighting functionality via the [Prism.js](http://prismjs.com/) syntax highlighter with lots of themes and plugins."
icon: code
author:
Expand Down
37 changes: 27 additions & 10 deletions prism-highlight.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,34 @@ public function onTwigSiteVariables()
$this->grav['assets']->addCss('plugin://prism-highlight/css/themes/' . $theme);
$this->grav['assets']->addJs('plugin://prism-highlight/js/prism.js', null, true, null, 'bottom');

$inline = '';
$all_pre_blocks = $this->config->get('plugins.prism-highlight.all-pre-blocks');
$line_numbers = $this->config->get('plugins.prism-highlight.plugins.line-numbers');
$command_line = $this->config->get('plugins.prism-highlight.plugins.command-line');

// Always add at least plain text language
if ($this->config->get('plugins.prism-highlight.all-pre-blocks')) {
$inline .= "$('pre:not([class*=\'language-\'])').addClass('language-txt');\n";
$inline = "";

if ($all_pre_blocks || $line_numbers || $command_line) {
$inline .= "var __prism_nodes = null;\n";
}

// Line Numbers management
if ($this->config->get('plugins.prism-highlight.plugins.line-numbers')) {
$inline .= "$('pre').addClass('line-numbers');\n";
// Always add at least plain text language
if ($all_pre_blocks) {
$inline .= "__prism_nodes = document.querySelectorAll('pre:not([class*=\"language-\"])');\n";
$inline .= $this->_addJsClass('language-txt');
}

// Command Line management
if ($this->config->get('plugins.prism-highlight.plugins.command-line')) {
$inline .= "$('pre').addClass('command-line');\n";
xdebug_break();
// Line Numbers management || Command Line management
if ($line_numbers || $command_line) {
$inline .= "__prism_nodes = document.querySelectorAll('pre');\n";

if ($line_numbers) {
$inline .= $this->_addJsClass('line-numbers');
}

if ($command_line) {
$inline .= $this->_addJsClass('command-line');
}
}

if ($inline) {
Expand All @@ -106,4 +119,8 @@ public static function themeOptions()

return $options;
}

private function _addJsClass($class = '') {
return "__prism_nodes.forEach(function(node) { node.classList.add('" . $class . "'); });\n";
}
}

0 comments on commit 7bfff69

Please sign in to comment.