Skip to content

Commit

Permalink
Add code highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Miloslav Nenadal committed Nov 20, 2020
1 parent eebff67 commit e41af3a
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ImaticFormatting.php
Expand Up @@ -8,7 +8,7 @@ public function register(): void
{
$this->name = 'Imatic formatting';
$this->description = 'Formatting';
$this->version = '0.0.2';
$this->version = '0.0.3';
$this->requires = [
'MantisCore' => '2.0.0',
];
Expand All @@ -26,6 +26,12 @@ public function hooks(): array
];
}

public function config(): array {
return [
'include_prism' => true,
];
}

private function getConverter(): GithubFlavoredMarkdownConverter
{
static $converter = null;
Expand All @@ -47,7 +53,17 @@ public function display_formatted_hook( $p_event, $p_string, $p_multiline = true
return $this->convert($p_string);
}

private function prism_includes() {
if (!plugin_config_get('include_prism', null, true)) {
return '';
}

return '<link rel="stylesheet" type="text/css" href="' . plugin_file('prism.css') . '&v=' . $this->version . '" />'
. '<script async type="text/javascript" src="' . plugin_file( 'prism.js' ) . '&v=' . $this->version . '"></script>';
}

public function layout_resources_hook() {
return '<link rel="stylesheet" type="text/css" href="' . plugin_file('styles.css') . '&v=' . $this->version . '" />';
return '<link rel="stylesheet" type="text/css" href="' . plugin_file('styles.css') . '&v=' . $this->version . '" />'
. $this->prism_includes();
}
}
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -3,3 +3,13 @@
# Imatic formatting

Converts markdown into html.


## Code highlighting

Following url was used to fetch code highlighting code: https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+clojure+markup-templating+php+sql

It can be disabled with:
```php
$g_plugin_ImaticFormatting_include_prism = false;
```
143 changes: 143 additions & 0 deletions files/prism.css
@@ -0,0 +1,143 @@
/* PrismJS 1.22.0
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+clojure+markup-templating+php+sql */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/

code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 1em;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;

-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;

-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}

pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}

pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}

@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}

/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}

.token.punctuation {
color: #999;
}

.token.namespace {
opacity: .7;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #9a6e3a;
/* This background color was intended by the author of this theme. */
background: hsla(0, 0%, 100%, .5);
}

.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}

.token.function,
.token.class-name {
color: #DD4A68;
}

.token.regex,
.token.important,
.token.variable {
color: #e90;
}

.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}

.token.entity {
cursor: help;
}

0 comments on commit e41af3a

Please sign in to comment.