Syntax-highlighting Code Block (with Server-side Rendering)

Beschreibung

Dieses Plugin erweitert den Code-Block im WordPress-Core um Syntax-Hervorhebung, die auf dem Server gerendert wird. Existierende Code-Blöcke auf einer Website werden automatisch um Syntax-Hervorhebung erweitert. Serverseitige Syntax-Hervorhebung macht das Einbinden eines JavaScripts im Frontend (z. B. Highlight.js oder Prism.js) überflüssig und es garantiert, dass es kein kurzes Aufblitzen des nicht hervorgehobenen Codes gibt (FOUC?). Durch das Reduzieren des Skripts im Frontend verbessert dessen Leistung und erlaubt auch eine vernünftige Syntax-Hervorhebung auf AMP-Seiten, die vom offiziellen AMP-Plugin (engl.) erstellt werden (siehe auch ampproject/amp-wp#972 (engl.)) oder wenn JavaScript im Browser deaktiviert ist.

Zusätzlich dazu, dass kein JavaScript zum Frontend hinzugefügt wird, wird das Stylesheet, um das Styling des Code-Blocks festzulegen, nur dann eingebunden, wenn es auf der Seite einen Code-Block gibt. Das Stylesheet wird inline eingebunden, wenn der Code-Block angezeigt wird, damit dieser nicht von anderen Stylesheets überschrieben wird. Wenn das Stylesheet aus irgendeinem Grund nicht geladen wird, wird der Block einfach ohne Styling angezeigt, mit einer kleinen Ausnahme: hervorgehobene Zeilen sind von mark-Elementen (engl.) umschlossen, sodass sie dennoch hervorgehoben werden, ebenfalls in RSS-Feeds und Beiträge, die als E-Mail versendet werden (solange diese das mark-Element im jeweiligen Programm unterstützen).

Der erweiterte Code-Block benutzt eine automatische Erkennung der Sprache, um die Syntax-Hervorhebung hinzuzufügen, aber du kannst die Sprache in den Einstellungen des Blocks innerhalb der Sidebar überschreiben. (Es gibt aktuell keine Syntax-Hervorhebung des Code-Blocks im Editor.) Das Plugin unterstützt alle Programmiersprachen (engl.), die highlight.php (engl.) unterstützt (das eine Portierung von highlight.js (engl.) ist). Der Code-Block wurde ebenfalls erweitert, um das Hervorheben einzelner Zeilen zu ermöglichen. Es gibt auch ein Auswahlkästchen, um einzustellen, ob die Zeilennummern im Frontend angezeigt werden soll (wobei die Nummern nicht auswählbar sind). Zuletzt, aufgrund Inkonsistenzen über Themes hinweg, ob die Zeilen im Code-Block umgebrochen werden sollen oder nicht, fügt dieses Plugin Styling hinzu, um sie standardmäßig nicht umbrechen zu lassen, mit einem Auswahlkästchen, sie umbrechen zu lassen, wenn gewünscht.

Für eine erweiterte Benutzer, schau dir bitte das Plugin-Wiki (engl.) an.

Dieses Plugin wird auf GitHub entwickelt (engl.). Siehe die Liste der aktuellen Probleme (engl.) des Plugins. Bitte zögere nicht, weitere Probleme oder Anfragen zu melden, auf die du stößt. Pull requests (engl.) sind willkommen.

Danksagungen

Dies ist ein Fork des Code-Syntax-Blocks (engl.) von Marcus Kazmierczak (engl.) (mkaz), welcher auch auf de.WordPress.org verfügbar ist. Copyright (c) 2018 Marcus Kazmierczak. Lizenziert unter GPL 2.0 oder später.

highlight.php (engl.) ist unter der BSD 3-Clause-Lizenz veröffentlicht. Copyright © 2006-2013, Ivan Sagalaev (maniac@softwaremaniacs.org), highlight.js (ursprünglicher Autor). Copyright © 2013, Geert Bergman (geert@scrivo.nl), highlight.php

Screenshots

  • Code-Blöcke können wie gewohnt hinzugefügt werden, optional mit Überschreiben der automatisch erkannten Sprache. Definiere auch Zeilen, die hervorgehoben werden sollen, ob Zeilennummern angezeigt und ob die Zeilen umgebrochen werden sollen.
  • Der Code-Block wird ohne JavaScript mit Syntax-Hervorhebung im Frontend dargestellt. Stylesheets werden nur hinzugefügt, wenn der Block auf der Seite ist.

Rezensionen

3. Juni 2023 1 Antwort
missed just a download and/or copy button. also for theme, maybe is best to update "usage instruction"! only after some search I understood can be changed via customized menu. anyway, looks so good. ty.
13. Juli 2022 1 Antwort
I confess, I've been a happy user of Code Syntax Block for quite a while — a plugin which the author, Weston Router, clearly states that Syntax Highlighting (Code Block) is based upon. Alas, however, all the pages I had with the older plugin would suffer from an inevitable rendering slowdown — there is so much Javascript on web pages these days that such a slowdown is inevitable, and this is especially true to those scripts that attempt to recognise the language automatically — something that will consume plenty of CPU cycles on the browser. Parsing the language is also no mean feature by itself (I know, I've been doing some experiments for some code editors, and, believe me, it's tough!). So why force the end-user to bear the burden of all that work? It makes much more sense to pre-render everything on the server, and then let the web server send the already-parsed HTML from its cache. That way, the end-user will already have everything on their browser, no need to wait for parsing! Also, if you 'forget' to set the language that your code is in (it happens...), the auto-detecting feature will only run on the server, and just once, when you save the post you're writing. Even if it takes a fraction of a second more to save, think of how much time all those users will save when they get the already-rendered page! So, this plugin is definitely recommended. As a bonus: if you are already using some sort of code block on your WP setup, once you turn off whatever plugin you were using, Syntax Highlighting (Code Block) will immediately pick it up and start its magic (you might need to open and save all the pages you've got code on, though — I'm not quite sure if that's really the case). That means zero effort (beyond saving) — what you already had will continue to work. And, naturally enough, when you disable this plugin, your code block will just revert to the internal WP code block instead — nothing will be 'lost' that way! If you're still hesitant and reading this to the end... while you wasted your time here, think of how many of your users would have saved their time if you already had this plugin installed 🙂
19. April 2022
No agrega bloques nuevos a WordPress, ya que potencia el bloque de código existente. Soporta gran cantidad de Lenguajes, puedes mostrar líneas y marcar ciertas partes del código. ¡Vaya todo lo que necesito! Y no hay que configurar nada!
21. Januar 2022
Just found this gem of a plugin when looking for code syntax highlighting plugins. No hassle at all to get working, just install and activate and it formats and styles existing code blocks in posts. Could not be happier with this plugin. Wlldone!
Alle 25 Rezensionen lesen

Mitwirkende & Entwickler

„Syntax-highlighting Code Block (with Server-side Rendering)“ ist Open-Source-Software. Folgende Menschen haben an diesem Plugin mitgewirkt:

Mitwirkende

„Syntax-highlighting Code Block (with Server-side Rendering)“ wurde in 8 Sprachen übersetzt. Danke an die Übersetzerinnen und Übersetzer für ihre Mitwirkung.

Übersetze „Syntax-highlighting Code Block (with Server-side Rendering)“ in deine Sprache.

Interessiert an der Entwicklung?

Durchstöbere den Code, sieh dir das SVN Repository an oder abonniere das Entwicklungsprotokoll per RSS.

Änderungsprotokoll

Bitte schaue auf die Release-Seite auf GitHub (engl.) für das Änderungsprotokoll des Plugins.