Skip to content

Early attempt at markdown rendering #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
229dfe4
Early attempt at rendering markdown on the commandline.
mcon Jan 1, 2021
b0c1c76
Add markdown text test.
mcon Jan 1, 2021
167e8ec
CanvasImage can take bytes to facilitate markdown rendering.
mcon Jan 2, 2021
9368218
Rule to take optional custom renderable to support markdown.
mcon Jan 2, 2021
1eb526c
Move Markdown to its own project due to dependency.
mcon Jan 2, 2021
63fb06c
Markdown tests to use their own project too, with sample markdown.
mcon Jan 2, 2021
5cb12ce
Create Markdown project for testing with proper terminal.
mcon Jan 2, 2021
69b59f8
Render bold/italic and thematic breaks
mcon Jan 2, 2021
485d843
Support strikethrough
mcon Jan 2, 2021
a479466
Handle quote blocks
mcon Jan 2, 2021
beb3b2c
Add emoji support to markdown
mcon Jan 2, 2021
df88973
Lists of lists have correct depth
mcon Jan 2, 2021
ac21380
Support numbered lists, also include verified output
mcon Jan 2, 2021
2a3e07c
Quotes now look like quotes, code blocks renderable
mcon Jan 2, 2021
1ce4a49
BlankLineBlock renders
mcon Jan 2, 2021
712f129
Code organization
mcon Jan 2, 2021
f1b345d
Able to render aligned tables
mcon Jan 3, 2021
afccf27
Fenced code blocks now render
mcon Jan 3, 2021
d8e383b
Separate block and inline rendering code
mcon Jan 3, 2021
78a7a1a
Configure markdown pipeline to not use CustomContainers or headers.
mcon Jan 3, 2021
3d6ec5d
Rearrange unimplemented features
mcon Jan 3, 2021
e67e8bd
Don't bother with abbreviations yet
mcon Jan 3, 2021
4cd0efd
Justify not including some data in output
mcon Jan 3, 2021
3ad323d
Don't bother using DefinitionLists
mcon Jan 3, 2021
5163b13
Don't bother with autolinks
mcon Jan 3, 2021
ddf94fe
Inline code and marking code blocks
mcon Jan 3, 2021
9ed92e3
Tidy up
mcon Jan 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions examples/Console/Markdown/Markdown.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<None Remove="Sample.md" />
<EmbeddedResource Include="Sample.md">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console.Markdig\Spectre.Console.Markdig.csproj" />
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions examples/Console/Markdown/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.IO;
using System.Reflection;
using Spectre.Console;

namespace MarkdownExample
{
class Program
{
static void Main(string[] args)
{
var resource = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("Markdown.Sample.md");
var markdown = new StreamReader(resource ?? throw new InvalidOperationException()).ReadToEnd();

var markdownWidget = new Markdown(markdown);

AnsiConsole.Render(markdownWidget);
}
}
}
245 changes: 245 additions & 0 deletions examples/Console/Markdown/Sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
---
__Advertisement :)__

- __[pica](https://nodeca.github.io/pica/demo/)__ - high quality and fast image
resize in browser.
- __[babelfish](https://github.com/nodeca/babelfish/)__ - developer friendly
i18n with plurals support and easy syntax.

You will like those projects!

---

# h1 Heading 8-)
## h2 Heading
### h3 Heading
#### h4 Heading
##### h5 Heading
###### h6 Heading


## Horizontal Rules

___

---

***


## Typographic replacements

Enable typographer option to see result.

(c) (C) (r) (R) (tm) (TM) (p) (P) +-

test.. test... test..... test?..... test!....

!!!!!! ???? ,, -- ---

"Smartypants, double quotes" and 'single quotes'


## Emphasis

**This is bold text**

__This is bold text__

*This is italic text*

_This is italic text_

~~Strikethrough~~


## Blockquotes


> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.


## Lists

Unordered

+ Create a list by starting a line with `+`, `-`, or `*`
+ Sub-lists are made by indenting 2 spaces:
- Marker character change forces new list start:
* Ac tristique libero volutpat at
+ Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
+ Very easy!

Ordered

1. Lorem ipsum dolor sit amet
2. Consectetur adipiscing elit
3. Integer molestie lorem at massa


1. You can use sequential numbers...
1. ...or keep all the numbers as `1.`

Start numbering with offset:

57. foo
1. bar


## Code

Inline `code`

Indented code

// Some comments
line 1 of code
line 2 of code
line 3 of code


Block code "fences"

```
Sample text here...
```

Syntax highlighting

``` js
var foo = function (bar) {
return bar++;
};

console.log(foo(5));
```

## Tables

| Option | Description |
| ------ | ----------- |
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |

Right aligned columns

| Option | Description |
| ------:| -----------:|
| data | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext | extension to be used for dest files. |


## Links

[link text](http://dev.nodeca.com)

[link with title](http://nodeca.github.io/pica/demo/ "title text!")

Autoconverted link https://github.com/nodeca/pica (enable linkify to see)


## Images

![Minion](https://octodex.github.com/images/minion.png)
![Stormtroopocat](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat")

Like links, Images also have a footnote style syntax

![Alt text][id]

With a reference later in the document defining the URL location:

[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat"


## Plugins

The killer feature of `markdown-it` is very effective support of
[syntax plugins](https://www.npmjs.org/browse/keyword/markdown-it-plugin).


### [Emojies](https://github.com/markdown-it/markdown-it-emoji)

> Classic markup: :wink: :ok_hand: :cry: :avocado: :laughing: :yum:
>
> Shortcuts (emoticons): :-) :-( 8-) ;)

see [how to change output](https://github.com/markdown-it/markdown-it-emoji#change-output) with twemoji.


### [Subscript](https://github.com/markdown-it/markdown-it-sub) / [Superscript](https://github.com/markdown-it/markdown-it-sup)

- 19^th^
- H~2~O


### [\<ins>](https://github.com/markdown-it/markdown-it-ins)

++Inserted text++


### [\<mark>](https://github.com/markdown-it/markdown-it-mark)

==Marked text==


### [Footnotes](https://github.com/markdown-it/markdown-it-footnote)

Footnote 1 link[^first].

Footnote 2 link[^second].

Inline footnote^[Text of inline footnote] definition.

Duplicated footnote reference[^second].

[^first]: Footnote **can have markup**

and multiple paragraphs.

[^second]: Footnote text.


### [Definition lists](https://github.com/markdown-it/markdown-it-deflist)

Term 1

: Definition 1
with lazy continuation.

Term 2 with *inline markup*

: Definition 2

{ some code, part of Definition 2 }

Third paragraph of definition 2.

_Compact style:_

Term 1
~ Definition 1

Term 2
~ Definition 2a
~ Definition 2b


### [Abbreviations](https://github.com/markdown-it/markdown-it-abbr)

This is HTML abbreviation example.

It converts "HTML", but keep intact partial entries like "xxxHTMLyyy" and so on.

*[HTML]: Hyper Text Markup Language

### [Custom containers](https://github.com/markdown-it/markdown-it-container)

::: warning
*here be dragons*
:::
5 changes: 5 additions & 0 deletions src/Spectre.Console.ImageSharp/CanvasImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public CanvasImage(string filename)
Image = SixLabors.ImageSharp.Image.Load<Rgba32>(filename);
}

public CanvasImage(byte[] data)
{
Image = SixLabors.ImageSharp.Image.Load<Rgba32>(data);
}

/// <inheritdoc/>
protected override Measurement Measure(RenderContext context, int maxWidth)
{
Expand Down
Loading