-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53d9efe
commit a06a355
Showing
466 changed files
with
20,724 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"pluginName":"Syntax Highlighter","pluginDescription":"The power of Prism syntax highlighting in Craft\r\n","pluginVersion":"1.0.0","pluginAuthorName":"Hashtag Errors","pluginVendorName":"hashtagerrors","pluginAuthorUrl":"http://hashtagerrors.com","pluginAuthorGithub":"hashtagerrors","codeComments":"","pluginComponents":["fieldtypes","settings"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# CRAFT ENVIRONMENT | ||
.env.php | ||
.env.sh | ||
.env | ||
|
||
# COMPOSER | ||
/vendor | ||
|
||
# BUILD FILES | ||
/bower_components/* | ||
/node_modules/* | ||
/build/* | ||
/yarn-error.log | ||
|
||
# MISC FILES | ||
.cache | ||
.DS_Store | ||
.idea | ||
.project | ||
.settings | ||
*.esproj | ||
*.sublime-workspace | ||
*.sublime-project | ||
*.tmproj | ||
*.tmproject | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
config.codekit3 | ||
prepros-6.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Syntax Highlighter Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## 1.0.0 - 2019-05-18 | ||
### Added | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Hashtag Errors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
|
||
|
||
# Syntax Highlighter | ||
|
||
The power of Prism syntax highlighting in Craft. | ||
|
||
![Screenshot](http://www.hashtagerrors.com/assets/uploads/prism.jpg) | ||
|
||
## Requirements | ||
|
||
This plugin requires Craft CMS 3.0.0 or later. | ||
|
||
## Installation | ||
|
||
To install the plugin, follow these instructions. | ||
|
||
1. Open your terminal and go to your Craft project: | ||
|
||
cd /path/to/project | ||
|
||
2. Then tell Composer to load the plugin: | ||
|
||
composer require hashtagerrors/syntax-highlighter | ||
|
||
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Syntax Highlighter. | ||
|
||
## Syntax Highlighter Overview | ||
|
||
**Syntax Highlighter Setting** | ||
|
||
[Prism](https://prismjs.com) is one of the most popular syntax highlighters that widely used by a lot of blog or websites due to it's ability to do custom builds of the language highlighter and plugins you want to be used. | ||
|
||
This plugin helps you to similarly build Prism files by selecting desired languages, plugins and theme and then finally bring code highlighter in frontend with a single line of code. | ||
|
||
Plugin setting page has 178 languages, 8 themes & 4 plugins to select from. Once you choose desired languages, theme and plugins, the plugin builds a JS and CSS file based on the selection which is then automatically fetched when called in frontend. | ||
|
||
![Screenshot](http://www.hashtagerrors.com/assets/uploads/prism-setting-page.jpg) | ||
|
||
**Syntax Highlighter Field** | ||
The plugin adds a `Syntax Highlighter` fieldtype which then displays a block to add your code, select code type, add a caption and specify the lines to be highlighted (if enabled in plugin setting). | ||
|
||
![Screenshot](http://www.hashtagerrors.com/assets/uploads/prism-fieldtype.jpg) | ||
|
||
**Syntax Highlighter Frontend** | ||
Using`{{ craft.syntaxHighlighter.render(entry.fieldHandle) }}` in template will show the highlighted code in the frontend. | ||
![Screenshot](http://www.hashtagerrors.com/assets/uploads/prism-frontend.jpg) | ||
|
||
## Configuring Syntax Highlighter | ||
|
||
The Plugin has following settings: | ||
|
||
**Choose Languages** (Required) | ||
Choose the Languages that should be enabled. As this is a required field atleast 1 language needs to be selected. | ||
Default `Markup, CSS, C-like, JavaScript, Twig`. | ||
|
||
**Default Language** | ||
The language that would be selected by default in the drop down menu in Code Block Field. | ||
Default `Twig` | ||
|
||
**Theme** | ||
The Prism theme you would like to enable in frontend. | ||
Default `Prism` | ||
|
||
**Line Numbers** | ||
To enable Line Numbers in the code block. Default | ||
Default `Prism` | ||
|
||
**Line Highlight** | ||
To enable Line Highlight in the code block. | ||
Default `True` | ||
|
||
**Show Language** | ||
To show language used in the code block. | ||
Default `False` | ||
|
||
**Copy to Clipboard Button** | ||
To enable Copy to Clipboard Button | ||
Default `True` | ||
|
||
**Max Height** | ||
To set maximum height(in px) of code container to avoid long scrolling in case of long code. | ||
Default `500` | ||
Leave empty or enter 0 to disable scroll. | ||
|
||
NOTE: Since this plugin build files every time it's plugin setting is saved, the plugin directory should have **Write** permission. specifically for the`hashtagerrors\syntax-highlighter\src\assetbundles\syntaxhighlighterfrontend` folder. | ||
|
||
## Using Syntax Highlighter | ||
|
||
1. Select desired languages, theme and plugin from setting page. | ||
2. Create a new field with `Syntax Highlighter` fieldtype. | ||
3. Add field in your section. | ||
4. Copy Paste or write down your code in the textarea of the the Code block, | ||
5. Select language from the Code Type dropdown. | ||
6. Enter line number(s) to be highlighted (if enabled in plugin setting). | ||
7. Add a Caption to show a text on below code block (optional). | ||
8. Use `{{ craft.syntaxHighlighter.render(entry.fieldHandle) }}` in template to show highlighted code. | ||
|
||
## Syntax Highlighter Roadmap | ||
|
||
* Ability to add custom CSS by user. | ||
* Prism's [File Highlight](https://prismjs.com/plugins/file-highlight/) plugin. | ||
* Prism's Other plugins. | ||
|
||
Brought to you by [Hashtag Errors](http://hashtagerrors.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "hashtagerrors/syntax-highlighter", | ||
"description": "The power of Prism syntax highlighting in Craft", | ||
"type": "craft-plugin", | ||
"version": "1.0.0", | ||
"keywords": [ | ||
"craft", | ||
"cms", | ||
"craftcms", | ||
"craft-plugin", | ||
"syntax highlighter" | ||
], | ||
"support": { | ||
"docs": "https://github.com/hashtagerrors/syntax-highlighter/blob/master/README.md", | ||
"issues": "https://github.com/hashtagerrors/syntax-highlighter/issues" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Hashtag Errors", | ||
"homepage": "http://hashtagerrors.com" | ||
} | ||
], | ||
"require": { | ||
"craftcms/cms": "^3.0.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"hashtagerrors\\syntaxhighlighter\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"name": "Syntax Highlighter", | ||
"handle": "syntax-highlighter", | ||
"hasCpSettings": true, | ||
"hasCpSection": false, | ||
"changelogUrl": "https://raw.githubusercontent.com/hashtagerrors/syntax-highlighter/master/CHANGELOG.md", | ||
"components": { | ||
"syntaxHighlighterService": "hashtagerrors\\syntaxhighlighter\\services\\SyntaxHighlighterService" | ||
}, | ||
"class": "hashtagerrors\\syntaxhighlighter\\SyntaxHighlighter" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
/** | ||
* Syntax Highlighter plugin for Craft CMS 3.x | ||
* | ||
* The power of Prism syntax highlighting in Craft | ||
* | ||
* @link http://hashtagerrors.com | ||
* @copyright Copyright (c) 2019 Hashtag Errors | ||
*/ | ||
|
||
namespace hashtagerrors\syntaxhighlighter; | ||
|
||
use hashtagerrors\syntaxhighlighter\models\Settings; | ||
use hashtagerrors\syntaxhighlighter\jobs\BuildFilesTask; | ||
use hashtagerrors\syntaxhighlighter\services\SyntaxHighlighterService; | ||
use hashtagerrors\syntaxhighlighter\variables\SyntaxHighlighterVariable; | ||
use hashtagerrors\syntaxhighlighter\fields\SyntaxHighlighterField as SyntaxHighlighterField; | ||
|
||
use Craft; | ||
use craft\base\Plugin; | ||
use craft\services\Plugins; | ||
use craft\services\Fields; | ||
use craft\events\PluginEvent; | ||
use craft\web\twig\variables\CraftVariable; | ||
use craft\events\RegisterComponentTypesEvent; | ||
|
||
use yii\base\Event; | ||
|
||
/** | ||
* Class SyntaxHighlighter | ||
* | ||
* @author Hashtag Errors | ||
* @package SyntaxHighlighter | ||
* @since 1.0.0 | ||
* | ||
*/ | ||
class SyntaxHighlighter extends Plugin | ||
{ | ||
// Static Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* @var SyntaxHighlighter | ||
*/ | ||
public static $plugin; | ||
|
||
// Public Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $schemaVersion = '1.0.0'; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
self::$plugin = $this; | ||
|
||
Event::on( | ||
Fields::class, | ||
Fields::EVENT_REGISTER_FIELD_TYPES, | ||
function (RegisterComponentTypesEvent $event) { | ||
$event->types[] = SyntaxHighlighterField::class; | ||
} | ||
); | ||
|
||
Event::on( | ||
Plugins::class, | ||
Plugins::EVENT_AFTER_INSTALL_PLUGIN, | ||
function (PluginEvent $event) { | ||
if ($event->plugin === $this) { | ||
$this->buildFiles(); | ||
} | ||
} | ||
); | ||
|
||
// when plugin settings are saved | ||
Event::on( | ||
Plugins::class, | ||
Plugins::EVENT_AFTER_SAVE_PLUGIN_SETTINGS, | ||
function (PluginEvent $event) { | ||
if ($event->plugin === $this) { | ||
$this->buildFiles(); | ||
} | ||
} | ||
); | ||
|
||
Event::on( | ||
CraftVariable::class, | ||
CraftVariable::EVENT_INIT, | ||
function (Event $event) { | ||
/** @var CraftVariable $variable */ | ||
$variable = $event->sender; | ||
$variable->set('syntaxHighlighter', SyntaxHighlighterVariable::class); | ||
} | ||
); | ||
|
||
Craft::info( | ||
Craft::t( | ||
'syntax-highlighter', | ||
'{name} plugin loaded', | ||
['name' => $this->name] | ||
), | ||
__METHOD__ | ||
); | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function createSettingsModel() | ||
{ | ||
return new Settings(); | ||
} | ||
public function availableLangauges() | ||
{ | ||
return SyntaxHighlighter::$plugin->syntaxHighlighterService->getAvailableLangauges(); | ||
} | ||
public function selectedLangauges() | ||
{ | ||
return SyntaxHighlighter::$plugin->syntaxHighlighterService->getSelectedLangauges(); | ||
} | ||
public function availableThemes() | ||
{ | ||
return SyntaxHighlighter::$plugin->syntaxHighlighterService->getAvailableThemes(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function settingsHtml(): string | ||
{ | ||
return Craft::$app->view->renderTemplate( | ||
'syntax-highlighter/settings', | ||
[ | ||
'settings' => $this->getSettings(), | ||
'langauges' => $this->availableLangauges(), | ||
'selectedLangauges' => $this->selectedLangauges(), | ||
'themes' => $this->availableThemes() | ||
] | ||
); | ||
} | ||
|
||
protected function buildFiles() | ||
{ | ||
Craft::$app->getQueue()->delay(0)->push(new BuildFilesTask()); | ||
} | ||
} |
Oops, something went wrong.