Markdown formatting on Hive: Correct display of code blocks for a template (AI-generated) (en/de)

in #wikiartikel10 months ago (edited)
Authored by @vanje

Introduction

Markdown is a widely used markup language for simple text formatting. On the Hive blockchain, Markdown is used to format content on platforms like PeakD, Ecency, and Hive.blog. However, there are platform-specific differences in how code blocks are displayed. This article explains how to properly display code blocks, especially using HTML entities and <pre> tags.

Basics of Markdown Formatting on Hive

Markdown supports various formatting options such as bold, italic, inline code, and code blocks. Code blocks are usually created using backticks (```) or tab indentation. For example:

# This is a heading
## This is a subheading
**Bold text** 
*Italic text*

However, not all Hive editors display these blocks correctly. Specifically, code blocks containing # or ## may be misinterpreted.

Problem: Code Blocks in PeakD

PeakD largely supports Markdown, but issues arise when trying to provide a copyable template with Markdown syntax. Specifically, # symbols for headings are interpreted as actual headings instead of being displayed as code.

Example of an Incorrect Code Block in PeakD:

# This should be a code block
## But the heading is rendered

In a template, you do not want to display the code in the rendered output:

image.png

Solution: Using HTML Entities and <pre>

To correctly display special characters like # and ## in a code block, a combination of HTML entities and the <pre> tag can be used. This preserves the formatting and allows users to copy the code directly.

Example Using HTML Entities and <pre>

image.png

The Code Block is Correctly Displayed:

# This is a heading
## This is a subheading
**Bold text**
*Italic text*

Advantages of This Method:

  • Proper display of Markdown syntax as code
  • No unintended conversion of headings or lists
  • Copyability is preserved

Additional Tips for Using Markdown on Hive

  • Consider platform differences: Markdown is interpreted differently on Hive frontends. Test your posts on PeakD, Ecency, and Hive.blog.
  • Use HTML replacements: In addition to <pre>, other HTML tags can be used to prevent incorrect Markdown interpretation.
  • Use live preview: Take advantage of the preview feature on PeakD or Ecency to identify formatting issues early.

Conclusion

Markdown formatting on Hive is a practical way to present content in a structured manner. However, due to platform differences, it may be necessary to use alternative methods such as HTML entities and <pre> tags to display code correctly. These techniques allow for the creation of copyable code templates, making it easier for users to reuse them.

Additional Resources

 

 

germany-flag-4%.png

Markdown-Formatierung in Hive: Korrekte Anzeige von Codeblöcken für ein Template

Einleitung

Markdown ist eine weit verbreitete Auszeichnungssprache zur einfachen Formatierung von Texten. Auf der Hive-Blockchain wird Markdown genutzt, um Inhalte auf Plattformen wie PeakD, Ecency oder Hive.blog zu formatieren. Allerdings gibt es Plattform-spezifische Unterschiede bei der Darstellung von Codeblöcken. Dieser Artikel beschreibt, wie Codeblöcke korrekt angezeigt werden können, insbesondere unter Verwendung von HTML-Entities und <pre>-Tags.

Grundlagen der Markdown-Formatierung auf Hive

Markdown unterstützt verschiedene Formatierungen wie fett, kursiv, Inline-Code und Codeblöcke. Für Codeblöcke werden in der Regel Backticks (```) oder Tabulator-Einrückungen genutzt. Beispielsweise:

# Dies ist eine Überschrift
## Dies ist eine Unterüberschrift
**Fetter Text** 
*Kursiver Text*

Doch nicht alle Hive-Editoren stellen diese Blöcke korrekt dar. Insbesondere können Codeblöcke mit # oder ## fehlerhaft interpretiert werden.

Problem: Codeblöcke in PeakD

Auf PeakD wird Markdown größtenteils unterstützt, jedoch treten Probleme auf, wenn man ein kopierbares Template mit Markdown-Syntax bereitstellen will. Insbesondere #-Zeichen für Überschriften werden als normale Überschrift erkannt und nicht als Code dargestellt.

Beispiel eines fehlerhaften Codeblocks in PeakD:

# Dies sollte ein Codeblock sein
## Doch die Überschrift wird gerendert

In einem Template möchten man den Code nicht in der gerenderten Ausgabe anzeigen:

image.png

Lösung: Verwendung von HTML-Entities und <pre>

Um auch Sonderzeichen wie # und ## in einem Codeblock korrekt anzuzeigen, kann eine Kombination aus HTML-Entities und dem <pre>-Tag verwendet werden. Damit bleibt die Formatierung erhalten und Nutzer können den Code direkt kopieren.

Beispiel mit HTML-Entities und <pre>

image.png

Der Codeblock wird jetzt korrekt dargestellt:

# Dies ist eine Überschrift
## Dies ist eine Unterüberschrift
**Fetter Text**
*Kursiver Text*

Vorteile dieser Methode:

  • Korrekte Anzeige von Markdown-Syntax als Code
  • Keine unbeabsichtigte Umwandlung von Überschriften oder Listen
  • Kopierbarkeit bleibt erhalten

Weitere Tipps für die Markdown-Nutzung auf Hive

  • Plattformabhängigkeit beachten: Markdown wird auf Hive-Frontends unterschiedlich interpretiert. Teste deine Beiträge auf PeakD, Ecency und Hive.blog.
  • HTML-Ersetzungen nutzen: Neben <pre> können weitere HTML-Tags genutzt werden, um Markdown-Fehlinterpretationen zu umgehen.
  • Live-Preview verwenden: Nutze die Vorschau-Funktion in PeakD oder Ecency, um Formatierungsprobleme frühzeitig zu erkennen.

Fazit

Die Markdown-Formatierung auf Hive ist eine praktische Möglichkeit, Inhalte strukturiert zu präsentieren. Aufgrund von Plattform-Unterschieden kann es jedoch notwendig sein, alternative Methoden wie HTML-Entities und <pre> zu nutzen, um Code korrekt darzustellen. Mit diesen Techniken lassen sich kopierbare Code-Templates erstellen, die Nutzern eine einfache Weiterverwendung ermöglichen.

Zusätzliche Ressourcen


This wiki article is based on a problem that I analyzed and worked out together with artificial intelligence. The content was created with the support of AI and then checked manually to ensure high quality and accuracy.