From decfe03cdaa32e73b39959377faf2d0081c19cdc Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 15 Nov 2019 00:27:23 +0100 Subject: [PATCH] Further work --- Classes/UserFunction/CodeHighlighting.php | 55 +++++++++ Configuration/RTE/Default.yaml | 72 +++++++++++ .../ContentElements/ParseFunc.typoscript | 114 ++++++++++++++++++ .../TypoScript/Setup/Page.typoscript | 42 ++++++- Configuration/TypoScript/setup.typoscript | 4 + .../Layouts/ContentElements/Default.html | 4 +- Resources/Private/Layouts/Page/Default.html | 103 +++------------- Resources/Private/Partials/Menu/Page.html | 18 ++- Resources/Private/Sass/_blog.scss | 108 ----------------- Resources/Private/Sass/_layout.scss | 15 ++- Resources/Private/Sass/_variables.scss | 64 ++++++++++ .../Sass/components/_codeHighlighting.scss | 46 +++++++ Resources/Private/Sass/index.scss | 22 ++-- Resources/Private/Sass/layout/_content.scss | 25 ++++ Resources/Private/Sass/layout/_elements.scss | 37 ++++++ Resources/Private/Sass/layout/_footer.scss | 4 + Resources/Private/Sass/layout/_header.scss | 23 ++++ .../Sass/layout/pages/_singleBlogPost.scss | 6 + .../Private/Templates/Page/BlogPost.html | 84 +++++++------ Resources/Private/Templates/Page/Default.html | 5 +- Resources/Public/Css/index.css | 8 +- composer.json | 8 +- ext_localconf.php | 3 + 23 files changed, 607 insertions(+), 263 deletions(-) create mode 100644 Classes/UserFunction/CodeHighlighting.php create mode 100644 Configuration/RTE/Default.yaml create mode 100644 Configuration/TypoScript/Setup/ContentElements/ParseFunc.typoscript delete mode 100644 Resources/Private/Sass/_blog.scss create mode 100644 Resources/Private/Sass/_variables.scss create mode 100644 Resources/Private/Sass/components/_codeHighlighting.scss create mode 100644 Resources/Private/Sass/layout/_content.scss create mode 100644 Resources/Private/Sass/layout/_elements.scss create mode 100644 Resources/Private/Sass/layout/_footer.scss create mode 100644 Resources/Private/Sass/layout/_header.scss create mode 100644 Resources/Private/Sass/layout/pages/_singleBlogPost.scss create mode 100644 ext_localconf.php diff --git a/Classes/UserFunction/CodeHighlighting.php b/Classes/UserFunction/CodeHighlighting.php new file mode 100644 index 0000000..545cc37 --- /dev/null +++ b/Classes/UserFunction/CodeHighlighting.php @@ -0,0 +1,55 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Highlight\Highlighter; +use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; + +/** + * Highlights the current value via library. + * Returns HTML Markup with css classes for proper highlighting. + */ +class CodeHighlighting +{ + /** + * @var ContentObjectRenderer + */ + public $cObj; + + public function preTag(string $content, array $config): string + { + $highlighter = new Highlighter(); + $highlighter->setClassPrefix(''); + $code = $this->cObj->data[$this->cObj->currentValKey]; + $code = htmlspecialchars_decode(trim($code)); + + try { + // Highlight some code. + $highlighted = $highlighter->highlightAuto($code); + $content = '
' . $highlighted->value . '
'; + } catch (DomainException $e) { + $content = '
' . $code . '
'; + } + + return $content; + } +} diff --git a/Configuration/RTE/Default.yaml b/Configuration/RTE/Default.yaml new file mode 100644 index 0000000..82b8810 --- /dev/null +++ b/Configuration/RTE/Default.yaml @@ -0,0 +1,72 @@ +# Load default processing options +imports: + - {resource: "EXT:rte_ckeditor/Configuration/RTE/Processing.yaml"} + - {resource: "EXT:rte_ckeditor/Configuration/RTE/Editor/Base.yaml"} + +editor: + config: + contentsCss: "EXT:ds_site/Resources/Public/Css/index.css" + height: 1000 + format_tags: "p;pre" + + # Ensure that special characters are not converted to HTML entities + entities_latin: false + entities: false + stylesSet: + - {name: "Inline code", element: "code"} + + toolbarGroups: + # - {name: insert} + - {name: basicstyles, groups: [basicstyles, align, cleanup]} + - {name: paragraph, groups: [list, indent, blocks, align, bidi]} + - {name: links} + - {name: editing, groups: [find, selection, spellchecker]} + - {name: specialcharacters, groups: [insertcharacters]} + - "/" + - {name: styles} + - "/" + - {name: tools} + - {name: document, groups: [mode, document, doctools]} + + # - {name: 'document', items: ['Source']} + # - {name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', 'Undo', 'Redo']} + # - '/' + # - {name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', 'CopyFormatting', 'RemoveFormat']} + # - {name: 'paragraph', items: ['NumberedList', 'BulletedList', 'Outdent', 'Indent', 'Blockquote']} + # - {name: 'links', items: ['Link', 'Unlink', 'Anchor']} + # - {name: 'insert', items: ['HorizontalRule', 'SpecialChar']} + # - '/' + # - {name: 'styles', items: ['Styles', 'Format']} + # - {name: 'tools', items: ['Maximize', 'ShowBlocks']} + # - {name: 'about', items: ['About']} + + externalPlugins: + typo3link: { resource: "EXT:rte_ckeditor/Resources/Public/JavaScript/Plugins/typo3link.js", route: "rteckeditor_wizard_browse_links" } + showbrokenlinks: { resource: "EXT:rte_ckeditor/Resources/Public/JavaScript/Plugins/showbrokenlinks/plugin.js"} + # This is a plugin, found here: https://github.com/ufdada/quicktable + # quicktable: { resource: "EXT:rte_ckeditor/Resources/Public/JavaScript/Plugins/quicktable/plugin.js" } + autolinking: { resource: "EXT:rte_ckeditor/Resources/Public/JavaScript/Plugins/autolinking.js" } + # softhyphen plugin for adding ctrl+dash support to insert a conditional word break + # softhyphen: + # resource: "EXT:rte_ckeditor/Resources/Public/JavaScript/Plugins/softhyphen/" + # enableShortcut: true + +processing: + allowAttributes: [class, title, start] + HTMLparser_db: + tags: + ol: + allowedAttribs: + - class + - start + allowTagsOutside: + - pre + - blockquote + - ul + - ol + - li + - br +# blockElementList: +# - P +# - PRE +# - BLOCKQUOTE diff --git a/Configuration/TypoScript/Setup/ContentElements/ParseFunc.typoscript b/Configuration/TypoScript/Setup/ContentElements/ParseFunc.typoscript new file mode 100644 index 0000000..0428bfd --- /dev/null +++ b/Configuration/TypoScript/Setup/ContentElements/ParseFunc.typoscript @@ -0,0 +1,114 @@ +# Creates persistent ParseFunc setup for non-HTML content. +lib.parseFunc { + makelinks = 1 + makelinks { + http { + keep = {$styles.content.links.keep} + extTarget = {$styles.content.links.extTarget} + } + mailto { + keep = path + } + } + tags { + link = TEXT + link { + current = 1 + typolink { + parameter.data = parameters : allParams + extTarget = {$styles.content.links.extTarget} + } + parseFunc.constants = 1 + } + pre = USER + pre { + userFunc = DanielSiepmann\DsSite\UserFunction\CodeHighlighting->preTag + } + a = TEXT + a { + current = 1 + typolink { + parameter.data = parameters:href + title.data = parameters:title + ATagParams.data = parameters:allParams + target.data = parameters:target + extTarget = {$styles.content.links.extTarget} + extTarget.override.data = parameters:target + } + } + } + allowTags = a, abbr, acronym, address, b, bdo, big, blockquote, br, caption, center, cite, code, dd, del, dfn, dl, div, dt, em, h3, h4, h5, h6, hr, i, img, ins, kbd, label, li, link, ol, p, pre, q, s, samp, sdfield, small, span, strike, strong, sub, sup, title, tt, u, ul, var + denyTags = * + sword = | + constants = 1 + nonTypoTagStdWrap { + HTMLparser = 1 + HTMLparser { + keepNonMatchedTags = 1 + htmlSpecialChars = 2 + } + } +} + +# Creates persistent ParseFunc setup for RTE content (which is mainly HTML) based on the "default" transformation. +lib.parseFunc_RTE < lib.parseFunc +lib.parseFunc_RTE { + # Processing
    ,