Giter Site home page Giter Site logo

grav-plugin-highlight's Introduction

Grav Highlight Plugin

Highlight

highlight is a Grav plugin that adds simple and powerful code highlighting functionality utilizing Highlight.js.

Highlight.js: v10.5.0
Highlight.js line numbers plugin: v2.8.0

Installation

Installing the Highlight plugin can be done in one of two ways. Our GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.

GPM Installation (Preferred)

The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's Terminal (also called the command line). From the root of your Grav install type:

bin/gpm install highlight

This will install the Highlight plugin into your /user/plugins directory within Grav. Its files can be found under /your/site/grav/user/plugins/highlight.

Manual Installation

To install this plugin, just download the zip version of this repository and unzip it under /your/site/grav/user/plugins. Then, rename the folder to highlight. You can find these files either on GitHub or via GetGrav.org.

You should now have all the plugin files under

/your/site/grav/user/plugins/highlight

NOTE: This plugin is a modular component for Grav which requires Grav, the Error and Problems plugins, and a theme to be installed in order to operate.

Usage

To best understand how Highlight works, you should read through the original project documentation.

You can override any default settings from the page headers:

eg:

---
title: Sample Code With Custom Theme
highlight:
    theme: monokai
---

```
@font-face {
  font-family: Chunkfive; src: url('Chunkfive.otf');
}

body, .usertext {
  color: #F0F0F0; background: #600;
  font-family: Chunkfive, sans;
}

@import url(print.css);
@media print {
  a[href^=http]::after {
    content: attr(href)
  }
}
```

You can also disable highlighting for a particular page if causes issues:

---
title: Sample Code with Highlight disabled
highlight:
    enabled: false
---

```
@font-face {
  font-family: Chunkfive; src: url('Chunkfive.otf');
}

body, .usertext {
  color: #F0F0F0; background: #600;
  font-family: Chunkfive, sans;
}

@import url(print.css);
@media print {
  a[href^=http]::after {
    content: attr(href)
  }
}
```

Further, you can also enable line numbers on a specific page, or globally (in highlight.yaml):

---
title: Sample Code with Highlight and line numbers enabled
highlight:
    enabled: true
    lines: true
---

Valid theme options include:

a11y-dark darcula nnfx-dark
a11y-light dark nord
agate default obsidian
an-old-hope docco ocean
androidstudio dracula paraiso-dark
arduino-light far paraiso-light
arta foundation pojoaque
ascetic github purebasic
atelier-cave-dark github-gist qtcreator_dark
atelier-cave-light gml qtcreator_light
atelier-dune-dark googlecode railscasts
atelier-dune-light gradient-dark rainbow
atelier-estuary-dark gradient-light routeros
atelier-estuary-light grayscale school-book
atelier-forest-dark gruvbox-dark school-book
atelier-forest-light gruvbox-light shades-of-purple
atelier-heath-dark highlightjs-line-numbers solarized-dark
atelier-heath-light hopscotch solarized-light
atelier-lakeside-dark hybrid srcery
atelier-lakeside-light idea stackoverflow-dark
atelier-plateau-dark ir-black stackoverflow-light
atelier-plateau-light isbl-editor-dark sunburst
atelier-savanna-dark isbl-editor-light tomorrow
atelier-savanna-light kimbie.dark tomorrow-night
atelier-seaside-dark kimbie.light tomorrow-night-blue
atelier-seaside-light learn tomorrow-night-bright
atelier-sulphurpool-dark lightfair tomorrow-night-eighties
atelier-sulphurpool-light lioshi vs
atom-one-dark magula vs2015
atom-one-dark-reasonable mono-blue xcode
atom-one-light monokai xt256
brown-paper monokai-sublime zenburn
codepen-embed night-owl
color-brewer nnfx

Check out a live demo of these themes.

Following languages are supported:

.properties JSON R
Apache config Kotlin Ruby
Bash Less Rust
C Lua SCSS
C# Makefile Shell Session
C++ Markdown SQL
CoffeeScript Nginx config Swift
CSS Objective-C TOML, also INI
Diff Perl Twig
Go PHP TypeScript
HTML, XML PHP Template Visual Basic .NET
HTTP Plain text YAML
Java Python
JavaScript Python REPL

Updating

As development for the Highlight plugin continues, new versions may become available that add additional features and functionality, improve compatibility with newer Grav releases, and generally provide a better user experience. Updating Highlight is easy, and can be done through Grav's GPM system, as well as manually.

GPM Update (Preferred)

The simplest way to update this plugin is via the Grav Package Manager (GPM). You can do this with this by navigating to the root directory of your Grav install using your system's Terminal (also called command line) and typing the following:

bin/gpm update highlight

This command will check your Grav install to see if your Highlight plugin is due for an update. If a newer release is found, you will be asked whether or not you wish to update. To continue, type y and hit enter. The plugin will automatically update and clear Grav's cache.

Manual Update

Manually updating Highlight is pretty simple. Here is what you will need to do to get this done:

  • Delete the your/site/user/plugins/highlight directory.
  • Downalod the new version of the Highlight plugin from either GitHub or GetGrav.org.
  • Unzip the zip file in your/site/user/plugins and rename the resulting folder to highlight.
  • Clear the Grav cache. The simplest way to do this is by going to the root Grav directory in terminal and typing bin/grav clear-cache.

Note: Any changes you have made to any of the files listed under this directory will also be removed and replaced by the new set. Any files located elsewhere (for example a YAML settings file placed in user/config/plugins) will remain intact.

grav-plugin-highlight's People

Contributors

bariscelik avatar dgellow avatar flaviocopes avatar olevik avatar rhukster avatar ryanmpierson avatar sal0max avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

grav-plugin-highlight's Issues

Monokai? Doesn't work for me

Hey guys,

I wanna start a blog and your lib is one of the things that I need so first of all thanks!
Tried some things yesterday but all I saw was a simple code block, so disabled was like enabled.
Today I simply changed the theme to github and everything works fine. Maybe there is an error with your "default" theme monokai so you might want to check it out!

Just an idea: For the user it would be nice to have some screenshots, maybe a gallery of the favorite themes :)

Have a nice day!

Opt-in - conditionally enable, not disable

Is this possible to have this plugin in "opt-in"? I have a blog with some articles with code, and some without. I would like to enable "highlight" only on those with code, rather than disable it on all the others. My main concern is the JS file, loaded everytime, even when there is no code to highlight. I tried enabled: false on config/plugins/highlight.yaml then

highlight:
  enabled: true

in the frontmatter of my article, but no luck (obviously).

If it's not possible, how can I make that? (via another plugin, or inside the theme)

Not work for me

install by command:

root@devnew /var/www/grav-admin # bin/gpm install highlight

GPM Releases Configuration: Stable



Preparing to install Highlight [v1.4.2]
  |- Downloading package...   100%.4%
  |- Checking destination...  ok
  |- Installing package...    ok
  '- Success!


Clearing cache

Cleared:  /var/www/grav-admin/cache/twig/*
Cleared:  /var/www/grav-admin/cache/doctrine/*
Cleared:  /var/www/grav-admin/cache/compiled/*

Touched: /var/www/grav-admin/user/config/system.yaml

root@devnew /var/www/grav-admin #

.. and not work

my site https://grav.mineland.net/primer-stati

page code: https://filebin.net/lpm64hkbs1j4yh43/page.txt?t=hmnz94he

Copy link scroll page to top

When I click on the copy link of a highlight button, the page scroll to top. There is no console error, the text is correctly copied in my clipboard

Grav RC5, Highlight plugin v1.2.0 with the RTFM theme

Control highlight from admin

I see an old issue #6 , but it was closed as uninteresting. It would be great to be able to tweak these settings from the admin panel (even it it was just under 'Options' like how some other plugins work e.g. mathjax)

highlight:
    theme: <value>
    enabled: true/false

Unformats py code

Hi

I am trying to embed some py code like

Class Draw:
	def __init__(self):
		self.vertices = []
		self.colors = []
		self.text = []
		

here is how it is in grav
screenshot_2019-01-22_20-56-30

Which renders like

screenshot_2019-01-asdsadsadsa-53-07

I am using it on Debian X64, Apache/2.4.37, PHP Version 7.1.20-1, Grav v1.5.6 - Admin v1.8.9

How to add new language?

Is there a way to add a language to this plugin? I'd like to add AppleScript, which is supported by Prism, but not included here.

Thanks.

highlight.js outdated

Thanks for this plugin, which is crucial for me as I often publish code.

I can see that the highlight.js demo has a style/theme that I'd love to use, but which isn't included in the Grav Highlight plugin.

Any chance that you can update the plugin to use the most recent version of highlight.js?

If not, do you accept sensible pull requests? I already manually added the new styles to my project but only spent energy on adding the A 11 Y Dark style/theme to blueprints.yaml as that was the one I was looking for.

P.S. I assume I'll have to redo my local patches once you make a new version, but that's life :-)

Defer loading of JavaScript

According to Google's PageSpeed Insights:

Eliminate render-blocking JavaScript and CSS in above-the-fold content. Your page has 1 blocking script resources and 3 blocking CSS resources. This causes a delay in rendering your page. None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML.

Remove render-blocking JavaScript:

https://www.example.com/user/plugins/highlight/js/highlight.pack.js

Can you please update the plug-in for loading JS files asynchronously?

Not working in Editorial Theme

Hello.

I can't get this plugin to work in editorial theme. In other themes it works fine, so I guess it must be something about the theme that I don't know.

I have uploaded a test page in the Editorial theme demo at the following address:
http://editorial.juanvillen.es/parent/child-one.

Grav and the plugin are on the latest version. I have set the lines and the monokai-blue theme. I can only see the lines in the code, but not the theme colors.

Any advice to fix this error?

Objective-C support?

Hi,

it looks like objective-c support is missing in the current version.
Possible that a update of highlight.js is needed for this.

Any ideas?

Styling has Disappeared Since 1.5

Hey - upgraded this plugin to the latest version v1.5.0 however it seems to have lost its ability to style <pre> text.

I have the site in a dev location and production one running the older version of the plugin and when you inspect the page you find that it is reading CSS stile from .hljs (in my case style sheet vs2015).

In 1.5 there this style sheet simply is not included.

I have tried:

  • Clear Cache
  • Disabled CSS & JS Pipeline
  • Custom Base URL changed to empty

I simply can't get the style sheet included. Any help would be much appreciated. Thanks

Line numbers not working

I use a pretty vanilla version of grav and the plugin works as expected but not for line numbers.

highlight:
lines: true

Does not change anything.
Line numbers are just not displayed.

I tested this on multiple themes.

Rust highlighting not working

The highlighter won't apply to Rust code.

Example:

```rust
fn main() {
    println!("WIP");
    let x = 34;
}
```

On Github, this renders as:

fn main() {
    println!("WIP");
    let x = 34;
}

On Grav, larger examples are auto-detected as either PHP or nginx in my experience. The class for the code block is parsed correctly and set to language-rust, but the highlighter doesn't apply (other languages use e.g., hljs php or hljs nginx).

HL version 1.4.0, Grav version 1.3.10, running in Docker.

Backend use?

Why not let this be used on the admin side too? That'd be cool.

Putting JS to the bottom

$this->grav['assets']->addJs('plugin://highlight/js/highlight.pack.js',array('group' => 'bottom' ));

would put the javascript file to the end of the page... that could help tweaking page-speed =)

missing language support

It seems the bundled highlight.pack.js only has the base set of languages. There were several additional ones I needed, so I downloaded a new highlight.pack.js. But I believe this will be overwritten if I update the plugin. For performance reasons, maybe it is not a good idea to bundle all languages, but it would be nice to be able to set a custom js file in the theme config.

Not working for me

I just installed this plugin via gpm, and most of my site is pretty vanilla still(Im using Gantry theme, anyway)
And it doesnt really highlight any code, doesnt show any error code or anything.
Im trying with the samples provided both here and on Grav's wiki.

It wont work with default Anttimater theme, either.
Im not really sure where I can get logs or something so its easier to provide help, but if you tell me I will provide all files necessary for diagnostic.
Thanks

Languages *say bash* not syntax highlighting

I tried some simple code:

```bash
echo $a
$a=20
```

Using default home page, and using the quark theme. I am using most current grav (with php 7.4.23), and caddy 2.4.3 with php-fpm.

If I change to ```js it renders, but no other languages seem to work. I have enabled the 'highlighting' plugin as well.

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.