Formatieren von Beiträgen mit Markdown, BBCode und HTML

:bookmark: This reference guide details all the formatting options available in Discourse posts, including markdown, BBCode, and HTML. It specifies what is supported and provides resources where you can see examples.

:person_raising_hand: Required user level: All users

Understanding supported formatting in posts

While plain text is sufficient for most replies, Discourse allows users to enhance the formatting of their posts by using markdown, BBCode, and HTML. This guide explains what types of formatting are supported and how you can use them effectively.

You can also practice some of the basics in an interactive tutorial by sending a personal message to @discobot here or on any Discourse site.

Summary

This guide covers:

  • Supported markdown syntax
  • Supported BBCode tags
  • Supported and safe HTML tags and attributes

Best practices

  • Use markdown primarily for its simplicity and readability.
  • Mix markdown and BBCode only when necessary, and keep usage consistent.
  • Limit the use of HTML to simple, safe tags to avoid formatting issues and ensure posts are secure.

Supported markdown

Discourse uses markdown-it for its markdown implementation.

Some commonly used markdown features include:

  • Bold: **text**
  • Italic: *text*
  • Link: [title](https://example.com)
  • Inline code: `code`
  • Highlight: <mark></mark>
  • Code block:
    ```
    code block
    ```
    

In longer posts (like this one), it can also be helpful to add structure using headings:

# Heading 1
## Heading 2
### Heading 3

Note: when an image is uploaded, the markdown syntax to reference the image will automatically be generated.

![caption|500x500](upload://image.jpeg)

For a full list of markdown features, please refer to the interactive guide.

Supported BBCode

Discourse supports a subset of common BBCode tags, some of which are generated automatically to support special formatting, for example when you quote a post in your reply:

[quote="user"]quoted text[/quote]

You can also use BBCode to mark hide text as a spoiler or as details

spoiled text

[spoiler]spoiled text[/spoiler]
click to expand

hidden text

[details="click to expand"]hidden text[/details]

BBCode tags for simple formatting supported by markdown or are also supported:

  • [b]strong[/b]
  • [i]emphasis[/i]
  • [u]underlined[/u]
  • [s]strikethrough[/s]
  • [ul][li]option one[/li][/ul]
  • [img]http://example.com/image.png[/img]
  • [url]http://example.com[/url]
  • [code]code[/code]

For a complete list of supported BBCode tags and examples, check the Discourse BBCode tests.

Supported HTML

Discourse supports a safe subset of HTML. While you can mix HTML with markdown, only specific HTML tags and attributes are allowed to ensure security and consistent styling.

Some of the allowed HTML tags include:

  • <a href="https://example.com">link</a>
  • <strong>bold text</strong>
  • <em>italic text</em>
  • <ul><li>list item</li></ul>
  • <img src="https://example.com/image.png" alt="description">

For a detailed list of allowed HTML tags and attributes, refer to Discourse’s allow-list.

:information_source: Note: Inline styles, like <span style="color:red">colored text</span>, are not supported. For custom styles, see customize post contents.

Common issues and solutions

  • BBCode or HTML tags not working: Ensure the tags you are using are part of the supported subset.
  • Inline styles being stripped: Discourse does not support inline styles for security reasons. Use custom styles or plugins if necessary.
  • Formatting changes on pasting from other editors: Some rich-text formats may not render correctly. Use markdown to format text consistently.

FAQs

Q: Can I use tables in Discourse?
A: Yes, you can use markdown to create tables. For more information, see this guide on tables.

Q: Why isn’t my inline style working?
A: Discourse does not support inline styles in HTML for security reasons. Consider using custom BBCode or the Discourse custom styling guide.

Q: Can I add custom BBCode tags?
A: Yes, you can add custom BBCode tags. Refer to the Discourse BBCode plugin for more information.

Additional resources

Last edited by @MarkDoerr 2024-07-11T00:31:08Z

Check documentPerform check on document:
31 „Gefällt mir“

Keine dieser Referenzen erwähnt Tabellen.

2 „Gefällt mir“

Das stimmt, aber dieses andere Thema schon. Adding a table to your post using markdown

2 „Gefällt mir“

Textfarbe und Text-Hintergrundfarbe scheinen mit <span> oder BBCode nicht zu funktionieren, übersehe ich etwas?

  • <span style="color:red">etwas roter Markdown-Text</span>
    • etwas roter Markdown-Text
  • BBCode: [color=red]Roter Text[/color]
    • [color=red]Roter Text[/color]
1 „Gefällt mir“

Ja, es sieht so aus, als ob HTML-Inline-Stile nicht unterstützt werden.

Sie können diesen Leitfaden verwenden:

(Und sehen Sie ihn hier in Aktion: 📜 [Wiki] Schlumpf hub serial numbers reference - Unicycles and Equipment - Unicyclist.com)

Oder verwenden Sie dieses Plugin, das die BBCode-Unterstützung erweitert:

Was die erlaubten HTML-Tags betrifft, glaube ich, dies ist die Referenz:
https://github.com/discourse/discourse/blob/main/app/assets/javascripts/pretty-text/addon/allow-lister.js#L115

Obwohl ich aus irgendeinem Grund keine Tabellen-HTML-Tags (die erlaubt sind) darin finden kann.

Vielleicht, weil sie hier referenziert werden:

https://github.com/discourse/discourse/blob/main/app/assets/javascripts/pretty-text/engines/discourse-markdown/table.js#L31

5 „Gefällt mir“

Vielen Dank für die nützlichen Referenzen!

1 „Gefällt mir“

Es sieht so aus, als ob der Filter derzeit so eingerichtet ist, dass die Attribute rowspan und colspan für td- und th-Elemente herausgefiltert werden. Soweit ich weiß, sind diese sicher (und ich glaube, sie sind sehr nützlich): Wäre das Team offen dafür, diese Attribute zuzulassen?

Nebenbei bemerkte @Canapin die Stelle, an der die erlaubte Liste von table-Tags aufgeführt ist.

Die Datei .../discourse-markdown/table.js scheint jedoch eine Implementierung speziell für Markdown-Tabellen zu sein; bräuchten reguläre HTML-Tabellen eine separate Erweiterung für allowList?

Ich glaube, rowspan und colspan sind ziemlich sicher, aber ich möchte auch ein weiteres Markup anfragen. Könnten wir data-*-Attribute für Tabellenelemente zulassen? Ich denke, das wäre sehr nützlich, um verschiedene Arten von Tabelleninhalten anzugeben, insbesondere als Hooks für benutzerdefiniertes CSS.

1 „Gefällt mir“

Hi :slight_smile:

Ich denke, das wäre kniffliger als erwartet.
Wenn Sie eine HTML-Tabelle in Ihren Beitrag einfügen und jemand Ihre Tabelle zitiert, wird sie in Markdown umgewandelt, das rowspan und colspan nicht unterstützt.

Ich vermute, es gäbe noch andere Probleme, über die ich nicht nachgedacht habe.

Es ist nicht genau dasselbe, aber Sie können Ihre Tabelle mit [wrap]-Tags umschließen :slight_smile:
Siehe: Customize posts' contents with your own styles
Aber Sie können keine data--Attribute innerhalb einer HTML-Tabelle haben (zum Beispiel, um bestimmte Zeilen oder Zellen anzupassen).

Bearbeitung: Wenn Ihre Tabelle Markdown anstelle von HTML verwendet, können Sie Spans mit data--Attributen wie folgt einfügen:

|Spalte 1 | Spalte 2|
|--- | ---|
|<span data-thing>Test</span> | Test|
|Test | Test|

Aber sie werden entfernt, wenn jemand Ihre Tabelle zitiert oder kopiert und einfügt.

1 „Gefällt mir“

Es wäre sehr hilfreich, wenn einige einfache und sichere Inline-CSS-Stile in rohem HTML, das zu Discourse-Beiträgen hinzugefügt wird, beachtet würden. Es könnten HTML-Beiträge von einer früheren Foren-Engine konvertiert werden und/oder Benutzer fügen manchmal Rich-Text mit Dingen wie Text- und/oder Bildausrichtung ein.

Das Folgende funktioniert wie erwartet:


<div align="center">
<p>Test</p>
</div>

Test

Aber das hier nicht:


<p style="text-align: center;">Test</p>

Test


Dasselbe gilt für Inline-Formatierungen wie <span style="color: ....

Es ist wahrscheinlicher, dass Inline-Stile wie diese in konvertierten / eingefügten Inhalten von anderen WYSIWYG-Editoren vorkommen.

Das style-Attribut ist in Discourse nicht erlaubt, da es leicht Probleme verursachen könnte.

Außerdem hat Discourse eine bestimmte Philosophie, wie Informationen in Beiträgen dargestellt werden sollen, und schränkt Tags und Attribute bewusst ein.

Das align-Attribut für <div> ist hier ausdrücklich erlaubt: https://github.com/discourse/discourse/blob/main/app/assets/javascripts/pretty-text/addon/allow-lister.js#LL147C2-L147C16

Wenn Sie ein Forum migrieren und spezielle Formatierungen wie Farben beibehalten möchten, würde ich Discourse BBCode verwenden und bei Bedarf den Importer bearbeiten :slight_smile:

3 „Gefällt mir“

Gibt es einen Grund, warum die > Blockquote-Markup nicht im Markdown-Abschnitt enthalten ist? Dies ist meiner Erfahrung nach bei weitem das häufigste, was die Leute nicht verwenden, obwohl sie es sollten.

Ich weiß, dass Sie nicht alles auflisten können, aber in Foren, in denen Leute oft andere Quellen zitieren, ist dies unerlässlich.

@one1, es sollte für Zitate innerhalb des Forums nicht verwendet werden. Sein Ersatz dort ist [quote]. Ansonsten stimme ich zu.

Ich sprach über Zitate aus wissenschaftlichen Arbeiten.

Das ist sehr hilfreich! Vielen Dank! :grinning_face: