Skip to content
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

Markdown.xaml enhanced #16

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions src/Markdown.Xaml.Demo/BoolToEnabledConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Markdown.Demo
{
class BoolToEnabledConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? false : true;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? false : true;
}
}
}
67 changes: 67 additions & 0 deletions src/Markdown.Xaml.Demo/DemoViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Markdown.Demo
{
class DemoViewModel : INotifyPropertyChanged
{

#region Properties

/// <summary>
/// Auto preview markdown when TRUE.
/// </summary>
public bool IsLive
{
get { return isLive; }
set { SetField(ref isLive, value); }
}
private bool isLive = true;

/// <summary>
/// Text for the editor.
/// </summary>
public string TextMarkdown
{
get { return textMarkdown; }
set
{
SetField(ref textMarkdown, value);
if (IsLive) TextPreview = textMarkdown;
}
}
private string textMarkdown = "";

/// <summary>
/// Text to preview.
/// </summary>
public string TextPreview
{
get { return textPreview; }
set { SetField(ref textPreview, value); }
}
private string textPreview = "";

#endregion Properties

#region PropertyChanged
public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
#endregion PropertyChanged
}
}
188 changes: 159 additions & 29 deletions src/Markdown.Xaml.Demo/MainWindow.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Markdown.Xaml #
|:-|
# Markdown.Xaml #

Markdown XAML is a port of the popular *MarkdownSharp* Markdown processor, but
with one very significant difference: Instead of rendering to a string
Expand All @@ -9,54 +10,183 @@ WPF window or usercontrol.

MarkDown.Xaml has a number of convenient features

* The engine itself is a single file, for easy inclusion in your own projects
* |:-|The engine itself is a single file, for easy inclusion in your own projects
* Code for the engine is structured in the same manner as the original MarkdownSharp
If there are any bug fixes to the regular expressions in MarkdownSharp, merging those fixes in the Markdown.Xaml should be straightforward
* Includes a `TextToFlowDocumentConverter` to make it easy to bind Markdown text

#
## Markdown capabilities and customizables styles: ##

## Markdown capabilities and customizables styles ##
######
#|:-:|***_BLOCK MARKDOWN_***
===



###***_Text Alignment_***
You can define the text alignment for the document (at the beginning) or a single paragraph (before text).

+ use |:-| or |-| or nothing° for left alignment
+ use |-:| for right alignment
+ use |:-:| for center alignment
+ use |=| for justify alignment

° "nothing" means left alignment only for the document; instead for the paragraphs "nothing" means the same alignment of the text defined for the document.



###***_Headings_***
"Text" accepts any _span markdown_.
Heading 1
=
Heading 2
-
Heading 2
-----------
# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
###### Heading 6 #######
######Heading 6



###***_Separators_***
---
===
***
___



###***_Lists_***
"Text" accepts any _span markdown_.

* First
* Level 2
+ Level 3
- Level 4
= Level 5
1. Level 6 First
2. Level 6 Second
* Second
a. Level 2 First
b. Level 2 Second
* Third
A. Level 2 First
B. Level 2 Second
* Fourth
i, Level 2 First
ii, Level 2 Second
* Fifth
I, Level 2 First
II, Level 2 Second



###***_Tables_***
"Text" accepts any _span markdown_.
|A|b|C|d|E|f|
|:-:|:-|-:|-|
|one|two|three|
|one|two|three|for|five|
|one|two|three|for|five|six|
|one|two|three|for|five|six|

|A|b|C|d|E|f|
=|:-:|:-|-:|-|
|one|two|three|
|one|two|three|for|five|
|one|two|three|for|five|six|
|one|two|three|for|five|six|

* Links [Go to Google!](https://www.google.com)
* Remote images

![image1](http://placehold.it/350x150)

![imageleft](http://placehold.it/100x150/0000FF)![imageright](http://placehold.it/100x150/00FFFF)
###***_Code Block_***
"Text" accepts any _span markdown_.
Text above
«text code block text code block text code block text code block text code block text code block text code block text code block text code block.»
Text below

* Local images

![localimage](sampleimage.jpg)

* Table
###***_Note_***
"Text" accepts any _span markdown_.
Text above
<text note text note text note text note text note text note text note text note text note text note text note text note text note text note.
Text below
< text note >

table begin string
|a|b|c|d|
|:-:|:-|-:|
|a1234567890|b1234567890|c1234567890|d1234567890|
|a|b|c|d|
table end string

This table is pre-formatted in text

| Alpha | Beta | Gamma | Delta |
|:-----------:|:------------|------------:|
| a1234567890 | b1234567890 | c1234567890 | d1234567890 |
|a | b | c | d |
###***_BlockQuotes_***
"Text" accepts any _span markdown_.
>Quote 1
>>Quote 2a
>>Quote 2b
>>> Quote 3
>>>>Quote 4 quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote quote
>>>>>>>>> Up to 9


* Separator
***


## What is this Demo? ##
######
___
#
#|:-:|***_SPAN MARKDOWN_***
===



###***_Text Decorations_***
+ *Italic*
+ **Bold**
+ ***BoldItalic***
+ _Underline_
+ __Strikethrough__
+ ___StrikethroughUnderline___
+ All combinations from *_TEXT_* to ***___TEXT___***



###***_Color_***
You can color text using color/[deepPink](color brush name), color/[#08F](hex) or color/[#88000000](hex with alpha).
"Text" inside () accepts any _span markdown_.



###***_Code Span_***
You can `highlight` the text.



###***_Links_***
This is a [link](https://www.google.com).

This is a [link with tooltip](https://www.google.com "Google").



###***_Images_***
_Remote images_:

![image1](http://placehold.it/350x150)

![#1](http://placehold.it/100x150/0000FF) ![#2](http://placehold.it/100x150/00FFFF)![#3](http://placehold.it/100x150/0000FF)![#4](http://placehold.it/100x150/00FFFF "right")

The image **#4** has the "right" tag which is used to set a different style for the image; in this case the style has Margin="20,0,0,0".

This demo application shows MarkDown.Xaml in use - as you make changes to the
left pane, the rendered MarkDown will appear in the right pane.
_Local image_:

### Source ###
![image2](sampleimage.jpg)

Review the source for this demo to see how MarkDown.Xaml works in practice, how to use the TextToFlowDocumentConverter,
and how to style the output to appear the way you desire.
_Fail to load image_:

![FailTest1]()

![FailTest2](ttp://placehold.it/100x150/0000FF)
Loading