Skip to content
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
4 changes: 2 additions & 2 deletions MarkdownDeep/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ internal bool ScanHtml(Block b)

// Safe mode?
bool bHasUnsafeContent = false;
if (m_markdown.SafeMode && !openingTag.IsSafe())
if ((m_markdown.SafeMode && !openingTag.IsSafe()) || !m_markdown.AllowUserHtml)
bHasUnsafeContent = true;

HtmlTagFlags flags = openingTag.Flags;
Expand Down Expand Up @@ -1481,7 +1481,7 @@ private Block BuildFootnote(List<Block> lines)
}

bool ProcessFencedCodeBlock(Block b)
{
{
char delim = current;

// Extract the fence
Expand Down
47 changes: 29 additions & 18 deletions MarkdownDeep/MardownDeep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public Markdown()
m_Footnotes = new Dictionary<string, Block>();
m_UsedFootnotes = new List<Block>();
m_UsedHeaderIDs = new Dictionary<string, bool>();
AllowUserHtml = true;
}

internal List<Block> ProcessBlocks(string str)
Expand Down Expand Up @@ -239,6 +240,16 @@ public bool MarkdownInHtml
set;
}

/// <summary>
/// Gets or sets whether the user can use html tags (like <u>) or whether all tags will be
/// quoted.
/// </summary>
public bool AllowUserHtml
{
get;
set;
}

// When set, all headings will have an auto generated ID attribute
// based on the heading text (uses the same algorithm as Pandoc)
public bool AutoHeadingIDs
Expand Down Expand Up @@ -316,15 +327,15 @@ public bool NoFollowLinks
set;
}

/// <summary>
/// Add the NoFollow attribute to all external links.
/// </summary>
public bool NoFollowExternalLinks
{
get;
set;
}
/// <summary>
/// Add the NoFollow attribute to all external links.
/// </summary>
public bool NoFollowExternalLinks
{
get;
set;
}



public Func<string, string> QualifyUrl;
Expand All @@ -343,9 +354,9 @@ public virtual string OnQualifyUrl(string url)
if (String.IsNullOrEmpty(UrlBaseLocation))
return url;

// Is the url a fragment?
if (url.StartsWith("#"))
return url;
// Is the url a fragment?
if (url.StartsWith("#"))
return url;

// Is the url already fully qualified?
if (Utils.IsUrlFullyQualified(url))
Expand Down Expand Up @@ -467,12 +478,12 @@ public virtual void OnPrepareLink(HtmlTag tag)
tag.attributes["rel"] = "nofollow";
}

// No follow external links only
if (NoFollowExternalLinks)
{
if (Utils.IsUrlFullyQualified(url))
tag.attributes["rel"] = "nofollow";
}
// No follow external links only
if (NoFollowExternalLinks)
{
if (Utils.IsUrlFullyQualified(url))
tag.attributes["rel"] = "nofollow";
}



Expand Down
2 changes: 1 addition & 1 deletion MarkdownDeep/SpanFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void Tokenize(string str, int start, int len)
HtmlTag tag = HtmlTag.Parse(this);
if (tag != null)
{
if (!m_Markdown.SafeMode || tag.IsSafe())
if ((!m_Markdown.SafeMode || tag.IsSafe()) && m_Markdown.AllowUserHtml)
{
// Yes, create a token for it
token = CreateToken(TokenType.HtmlTag, save, position - save);
Expand Down
7 changes: 4 additions & 3 deletions MarkdownDeepJS/MarkdownDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ var MarkdownDeep = new function () {
FormatCodeBlockAttributes: null,
FormatCodeBlock: null,
ExtractHeadBlocks: false,
HeadBlockContent: ""
HeadBlockContent: "",
AllowUserHtml: true
};

var p = Markdown.prototype;
Expand Down Expand Up @@ -2017,7 +2018,7 @@ var MarkdownDeep = new function () {
var tag = ParseHtmlTag(p);
if (tag != null) {
// Yes, create a token for it
if (!this.m_Markdown.SafeMode || tag.IsSafe()) {
if ((!this.m_Markdown.SafeMode || tag.IsSafe()) && this.m_Markdown.AllowUserHtml) {
// Yes, create a token for it
token = this.CreateToken(TokenType_HtmlTag, save, p.m_position - save);
}
Expand Down Expand Up @@ -3760,7 +3761,7 @@ var MarkdownDeep = new function () {

// Safe mode?
var bHasUnsafeContent = false;
if (this.m_Markdown.SafeMode && !openingTag.IsSafe())
if ((this.m_Markdown.SafeMode && !openingTag.IsSafe()) || !this.m_Markdown.AllowUserHtml)
bHasUnsafeContent = true;

var flags = openingTag.get_Flags();
Expand Down
334 changes: 167 additions & 167 deletions MarkdownDeepJS/MarkdownDeep.min.js

Large diffs are not rendered by default.

334 changes: 167 additions & 167 deletions MarkdownDeepJS/MarkdownDeepLib.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions MarkdownDeepTests/JSTestResources/MarkdownDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ var MarkdownDeep = new function () {
FormatCodeBlockAttributes: null,
FormatCodeBlock: null,
ExtractHeadBlocks: false,
HeadBlockContent: ""
HeadBlockContent: "",
AllowUserHtml: true
};

var p = Markdown.prototype;
Expand Down Expand Up @@ -2017,7 +2018,7 @@ var MarkdownDeep = new function () {
var tag = ParseHtmlTag(p);
if (tag != null) {
// Yes, create a token for it
if (!this.m_Markdown.SafeMode || tag.IsSafe()) {
if ((!this.m_Markdown.SafeMode || tag.IsSafe()) && this.m_Markdown.AllowUserHtml) {
// Yes, create a token for it
token = this.CreateToken(TokenType_HtmlTag, save, p.m_position - save);
}
Expand Down Expand Up @@ -3760,7 +3761,7 @@ var MarkdownDeep = new function () {

// Safe mode?
var bHasUnsafeContent = false;
if (this.m_Markdown.SafeMode && !openingTag.IsSafe())
if ((this.m_Markdown.SafeMode && !openingTag.IsSafe()) || !this.m_Markdown.AllowUserHtml)
bHasUnsafeContent = true;

var flags = openingTag.get_Flags();
Expand Down
Loading