PHP and Javascript implementations of a simple markdown parser
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

markdown.md 11KB

Markdown Syntax

Block Formats

Formats that apply to one or more lines.

Paragraph

Any contiguous set of lines not formatted like one of the other formats below is treated as a paragraph. Paragraphs are separated by double blank lines.

Lorem ipsum dolor
sit amet.

New paragraph begins.

Lorem ipsum dolor sit amet.

New paragraph begins.

Class:

  • MDParagraphReader

Headers

Headers are marked with one or more leading hashes.

# Header 1 has one hash

## Header 2 has two hashes

###### Up to header 6

## Optional Matched Hashes At The End ##

Header 1 has one hash

Header 2 has two hashes

Up to header 6

Optional Matched Hashes At The End

Alternately, H1 and H2 can be marked with underlines.

Header 1 underlined with equals
===============================

Header 2 with hyphens. Number of underline chars doesn't matter
---

Header 1 underlined with equals

Header 2 with hyphens. Number of underline chars doesn't matter

Classes:

  • MDUnderlinedHeadingReader
  • MDHashHeadingReader

Lists

Unordered lists are bulleted with an asterisk, plus, or hyphen and space.

* Item
+ Any of these
- Work as bullets
  • Item
  • Any of these
  • Work as bullets

Lists can be nested with one or more spaces below an item.

* Item
    * Sublist
	* Sublist
* Item
  • Item
    • Sublist
    • Sublist
  • Item

Ordered lists start with a number, period, and space.

1. Item
2. Item
3. Item
  1. Item
  2. Item
  3. Item

Again, they can be nested.

1. Item
    1. Subitem
	2. Subitem
2. Item
  1. Item
    1. Subitem
    2. Subitem
  2. Item

The first number dictates where the numbering begins. The numbers on the other items are ignored and incremented by one.

5. Rendered as a 5
1. Rendered as a 6
1. Rendered as a 7
  1. Rendered as a 5
  2. Rendered as a 6
  3. Rendered as a 7

Numbering every item with 1. can save you the hassle of renumbering items when reordering them.

Classes:

  • MDUnorderedListReader
  • MDOrderedListReader

Blockquote

Blockquotes enclose lengthy quoted content in an indented block.

Lorem Ipsum said:

> Dolor sit amet
> adipiscing.

Lorem Ipsum said:

Dolor sit amet adipiscing.

Class:

  • MDBlockQuoteReader

Code Blocks

Blocks of preformatted code can be enclosed in triple backticks.

`​``
function foo() {
	return 'bar';
}
`​``

function foo() {
    return 'bar';
}

Alternately, lines indented by at least four spaces or a tab character will be interpreted as code blocks.

    function foo() {
		return 'bar';
	}

function foo() {
    return 'bar';
}

Classes:

  • MDFencedCodeBlockReader
  • MDIndentedCodeBlockReader

Horizontal Rule

Horizontal divider lines are written as 3 or more hyphens or asterisks on a line by themselves, with or without interstitial whitespace.

---

***

- - - -

* * * * * * *




Class:

  • MDHorizontalRuleReader

Tables

Tables consist of one header row and any number of body rows

Header   | Row | Here
---------|-----|-----
Cell     | 123 |  xyz
Next row | 543 |  abc
HeaderRowHere
Cell123xyz
Next row543abc

The pipe characters do not have to line up.

Rows can optionally have leading and/or trailing pipes. This is required for a single column table.

| One column |
| --- |
| 123 |
| 234 |
One column
123
234

Columns can be right, center, or left aligned with colons in the divider line.

| Left | Center | Right |
| :--- | :----: | ----: |
| 1 | 2 | 3 |
LeftCenterRight
123

Tables can optionally support simple spreadsheet expressions by adding the spreadsheet block reader when configuring a parser.

Classes:

  • MDTableReader
  • MDSpreadsheetReader

Definition List

Definition lists show terms with definitions below them. Useful for glossaries.

term
: definition of term
another
: definition of another
: alternate definition of another
term
definition of term
another
definition of another
alternate definition of another

Class:

  • MDDefinitionListReader

Abbreviation Definition

Abbreviations can be defined anywhere in the document. Anywhere that abbreviation appears in the document will have a mouseover title showing the expanded definition. The definition is plaintext only (no markdown).

Always remember, ABC.

*[ABC]: Always Be Closing

Always remember, ABC.

Class:

  • MDAbbreviationReader

CSS Modifiers

Many block structures can be modified with CSS classes, IDs, or other simple HTML attributes inside curly braces.

## Header with a CSS class {.mycssclass}

--- {#mydividerid}

| Table | {style=color:green;}
|---|
|123|

## Header with multiple modifiers {.linkclass #linkid lang=en}

Header with a CSS class


Table
123

Header with multiple modifiers

Class:

  • MDModifierReader

Inline Formats

Formats that apply within a block to style runs of words or inject other content within text.

To prevent a punctuation character from being interpreted as formatting syntax, prefix the character with a backslash (\\). E.g. 3\*4\*2=24 is rendered as “3*4*2=24”, not as “3*4*2=24”.

Strong

Text can be marked as bold by enclosing it in double asterisks.

Some **bold** text. Can also use __underscores__ (unless underlining is enabled).

Some bold text. Can also use underscores (unless underlining is enabled).

Class:

  • MDStrongReader

Emphasis

Text can be marked as italic by enclosing it in single underscores or single asterisks.

Some _italic_ text. Can also use *asterisks*.

Some italic text. Can also use asterisks.

Class:

  • MDEmphasisReader

Strikethrough

Text can be stricken out using tildes, singly or in pairs. If subscript is enabled then only double tildes can be used.

Not ~~this text~~. Not ~this text~ either.

Not this text. Not this text either.

Class:

  • MDStrikethroughReader

Underline

Underline is denoted with double underscores. If this reader is in use, “strong” styling can only be done with double asterisks.

Some __underlined__ text.

Some underlined text.

Class:

  • MDUnderlineReader

Highlighting

Highlighting is done with pairs of equals around text.

Some ==highlighted== text.

Some highlighted text.

Class:

  • MDHighlightReader

Code

Words can be rendered in monospace font using single backticks.

The name of the function is `foo()`.

The name of the function is foo().

Class:

  • MDCodeSpanReader

Subscript

Subscript is denoted with single tildes around the text.

The formula for water is H~2~O.

The formula for water is H2O.

Class:

  • MDSubscriptReader

Superscript

Superscript is represented with caret characters around the text.

Einstein's equation E=mc^2^.

Einstein’s equation is E=mc2.

Class:

  • MDSuperscriptReader

Link

Linking to a document is done with marked text and a URL.

Click [here](page.html).

Click here.

An optional mouseover title can be added to the link after the URL.

Click [here](page.html "Goes to a neat page").

Click here.

Repetitive or lengthy URLs can be referenced out and defined elsewhere in the document.

Click [here][foo] or [here][foo] or [even here][foo] to go to the same place.

[foo]: page.html "Optional title"

Click here or here or even here to go to the same place.

Lastly, to make a link with the URL as the link text, you can use angle brackets.

Go visit <page.html>.

Go visit page.html.

Classes:

  • MDLinkReader
  • MDReferencedLinkReader

Image

An image is similar to link syntax with an exclamation in front. Instead of clickable link text, the text is alt text for the image.

![a test image](https://picsum.photos/100/75)

a test image

Images also support title attributes.

![a test image](https://picsum.photos/100/75 "title text")

a test image

Images also support referenced URLs.

![alt text][foo]

[foo]: https://picsum.photos/100/75

alt text

Images can be made clickable by enclosing them in a link where the link text goes.

[![alt text](https://picsum.photos/100/75)](page.html)

alt text

Classes:

  • MDImageReader
  • MDReferencedImageReader

Footnote

Footnotes can be inserted into text. The text of the footnotes is added to the bottom of the document, regardless of where they’re defined.

Lorem ipsum[^1] dolor sit[^2] amet.

[^1]: Further information here
[^2]: See _Interesting Book_, pg 213

Lorem ipsum1 dolor sit2 amet.


  1. Further information here ↩︎
  2. See Interesting Book, pg 213 ↩︎

Class:

  • MDFootnoteReader

HTML Tags

HTML tags can be used verbatim where markdown is too limiting.

The allowable tags, attributes, and CSS are governed by Markdown.tagFilter which is a configurable MDHTMLFilter object. Anything not excplicitly included in the filter is rendered as plain text or stripped from the output. For example, Javascript event hooks are disallowed, as are scripts, stylesheets, and iframes, among many others.

Class:

  • MDHTMLTagReader