grahamegrieve / delphi-markdown Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Try convert string with a lone bracket mark at the beginning of the line:
some text
<
other text
this raised Range Check exception
Using master branch with MarkdownDaringFireball option.
I have a TMemo where in OnChange event I convert markdown to html
When I write the following text:
simple text
<h1 style="background-color: green">css test<
It hangs as soon as I type the final "<"
I found the problem in:
MarkdownDaringFireball.TLine.checkHTML: boolean;
I fix it with following change:
line := self;
while (line <> nil) do
begin
// while (position < Length(line.value)) and (line.value[1 + position] <> '<') do
while (position < Length(line.value)) and ((line.value[1 + position] <> '<') or (position = Length(line.value)-1)) do
inc(FPosition);
if (position >= Length(line.value)) then
begin
line := line.next;
position := 0;
https://en.wikipedia.org/wiki/Markdown
cite from wiki:
"Two spaces at the end of a line leave a
line break.
=>
<p>Two spaces at the end of a line leave a<br />
line break.</p>"
function TLine.stripID(): String;
var
p, start: integer;
found: boolean;
id: String;
begin
if (isEmpty or (value[1 + Length(value) - trailing - 1] <> '}')) then
exit('');
p := leading;
found := false;
while (p < Length(value)) and (not found) do
begin
case value[1 + p] of
'\':
begin
if (p + 1 < Length(value)) then
begin
if (value[1 + p + 1]) = '{' then
begin
inc(p);
break;
end;
end;
inc(p);
break;
end;
'{':
begin
found := true;
break;
end
else
begin
inc(p);
end;
end;
end;
if (found) then
begin
found := false;
if (p + 1 < Length(value)) and (value[1 + p + 1] = '#') then
begin
start := p + 2;
p := start;
while (p < Length(value)) and (not found) do
begin
case (value[1 + p]) of
'\':
begin
if (p + 1 < Length(value)) then
begin
if (value[1 + p + 1]) = '}' then
begin
inc(p);
break;
end;
end;
inc(p);
break;
end;
'}':
begin
found := true;
break;
end;
else
begin
inc(p);
end;
end;
end;
end;
end;
if (found) then
begin
id := Trim( Copy(value, start + 1, p-start));
if (leading <> 0) then
begin
value := Copy(value, 1, leading) + Trim( Copy( value, leading + 1, start -2));
end
else
begin
value := Trim( Copy(value, leading +1, start -2));
end;
trailing := 0;
if (Length(id) > 0) then
exit(id)
else
exit('');
end;
exit('');
end;
Is it possible to use url with spaces for images and links?
I need to replace " " to %20 for the URL to work.
Example:
Does not show icon due to space in ulr:
![Icon](C:\Google Drive\app-icon-120.png)
Shows the icon normally after replacing " " to %20:
---
![Icon](C:\Google%20Drive\app-icon-120.png)
Is it possible to allow markdown parser to understand spaces in url?
Or maybe there could be some kind of a callback function which will allow to replace space in urls dynamically on the fly?
Using the CommonMark engine. Where < >
appears, substitute with an actual U+00A0 character.
It appears that some kind of punctuation is also required before the closing emphasis delimiter, or else this bug does not arise.
**First Line?**< >\
\
Second **Line**
<p><strong>First Line?</strong>< ><br />
<br />
Second <strong>Line</strong>.</p>
<p><strong>First Line?<strong>< ><br />
<br />
Second </strong>Line</strong>.</p>
For some reason, instead of closing the first <strong>
tag, the second emphasis delimiter turns into a second opening <strong>
tag.
I've tried alternative constructs, such as...
< >
with a normal space< >
with punctuation< >
positions...but none of those changes seemingly trigger the bug.
I cloned https://github.com/pleriche/FastMM4.git and https://github.com/VSoftTechnologies/DUnitX.git, corrected pathes accordingly.
Trying to compile delphi/MarkDownTests.dproj
I got these issues:
FastMM4 should be first in uses
list.
I don't know where to get TestInsight
, so I commented out the lines in sourcecode. TESTINSIGHT
variable is set in MarkDownTests.dproj
exe file is compiled inside delphi-markdown\delphi\
dir, so I copied resources
dir here.
Finally all set and running, but I got this:
* DUnitX - (c) 2015-2018 Vincent Parrett & Contributors *
* *
* License - http://www.apache.org/licenses/LICENSE-2.0 *
**********************************************************************
DUnitX - [MarkDownTests.exe] - Starting Tests.
.........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F.........................................................................................................................................................................................................................................................................................................................F.F.F.....F.........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F.........................................................................................................................................................................................................................................................................................................................................F.F.F.....F........................................................................................................................................................................................................
Tests Found : 978
Tests Ignored : 0
Tests Passed : 968
Tests Leaked : 0
Tests Failed : 10
Tests Errored : 0
Failing Tests
MarkdownCommonMarkTests.TMarkdownCommonMarkTest.TestCase.0309
Message: Expected <p><a href="/f%C3%B6%C3%B6" title="foo">foo</a></p>
is not equal to actual <p><a href="/foo" title="foo">foo</a></p>
output does not match expected for input "[foo](/föö "föö")
"
MarkdownCommonMarkTests.TMarkdownCommonMarkTest.TestCase.0473
Message: Expected <p><a href="foo%5Cbar">link</a></p>
is not equal to actual <p><a href="foo\bar">link</a></p>
output does not match expected for input "[link](foo\bar)
"
MarkdownCommonMarkTests.TMarkdownCommonMarkTest.TestCase.0474
Message: Expected <p><a href="foo%20b%C3%A4">link</a></p>
is not equal to actual <p><a href="foo%20ba">link</a></p>
output does not match expected for input "[link](foo%20bä)
"
MarkdownCommonMarkTests.TMarkdownCommonMarkTest.TestCase.0475
Message: Expected <p><a href="%22title%22">link</a></p>
is not equal to actual <p><a href=""title"">link</a></p>
output does not match expected for input "[link]("title")
"
MarkdownCommonMarkTests.TMarkdownCommonMarkTest.TestCase.0478
Message: Expected <p><a href="/url%C2%A0%22title%22">link</a></p>
is not equal to actual <p><a href="/url "title"">link</a></p>
output does not match expected for input "[link](/url "title")
"
MarkdownCommonMarkTests.TMarkdownGFMTest.TestCase.0322
Message: Expected <p><a href="/f%C3%B6%C3%B6" title="foo">foo</a></p>
is not equal to actual <p><a href="/foo" title="foo">foo</a></p>
output does not match expected for input "[foo](/föö "föö")
"
MarkdownCommonMarkTests.TMarkdownGFMTest.TestCase.0493
Message: Expected <p><a href="foo%5Cbar">link</a></p>
is not equal to actual <p><a href="foo\bar">link</a></p>
output does not match expected for input "[link](foo\bar)
"
MarkdownCommonMarkTests.TMarkdownGFMTest.TestCase.0494
Message: Expected <p><a href="foo%20b%C3%A4">link</a></p>
is not equal to actual <p><a href="foo%20ba">link</a></p>
output does not match expected for input "[link](foo%20bä)
"
MarkdownCommonMarkTests.TMarkdownGFMTest.TestCase.0495
Message: Expected <p><a href="%22title%22">link</a></p>
is not equal to actual <p><a href=""title"">link</a></p>
output does not match expected for input "[link]("title")
"
MarkdownCommonMarkTests.TMarkdownGFMTest.TestCase.0498
Message: Expected <p><a href="/url%C2%A0%22title%22">link</a></p>
is not equal to actual <p><a href="/url "title"">link</a></p>
output does not match expected for input "[link](/url "title")
"
Done.. press <Enter> key to quit.
This module is not part of the standard fpc libraries, but is an integral part of Lazarus
Thus, it is desirable to remove this dependency, because when compiling a standard fpc, it is necessary to pull up extra libraries.
Maybe this option will work?
function unicodeChars(s : String) : TArray<UnicodeChar>;
var
i, l: integer;
us: UnicodeString;
begin
us := UTF8Decode(s);
l := Length(us);
SetLength(result, l);
for i:=1 to l do result[i-1] := us[i];
end;
Text:
Expected html: mailto:[email protected]
Actual html: mailto:email(example.com
Markdown dialect used: mdDaringFireball
you can use TPoint (it is record of X, Y).
Two independent list is coverted to one list:
* simple list
* without
* number
1. list
2. with
3. numbered items
=>
<ul>
<li><p>simple list</p>
</li>
<li><p>without</p>
</li>
<li><p>number</p>
</li>
<li><p>list</p>
</li>
<li><p>with</p>
</li>
<li><p>numbered items</p>
</li>
</ul>
Visual result:
simple list
without
number
list
with
numbered items
But expected result is:
<ul>
<li><p class="parags">simple list</p>
</li>
<li><p class="parags">without</p>
</li>
<li><p class="parags">number</p>
</li>
</ul>
<ol>
<li><p class="parags">list</p>
</li>
<li><p class="parags">with</p>
</li>
<li><p class="parags">numbered items</p>
</li>
</ol>
Visual result:
simple list
without
number
list
with
numbered items
Using the CommonMark engine. When a number follows a numbered list (e.g. 1. 7
), a Range Check Error is thrown.
1. 7
<ol>
<li>7</li>
</ol>
No output. A Range Check Error is thrown on this line instead:
delphi-markdown/source/MarkdownCommonMark.pas
Line 2307 in 9f34d00
First of all, congratulations for the library.
I integrated it in this project:
https://github.com/EtheaDev/MarkdownShellExtensions
to be able to edit .md files with an editor and have a preview in Windows Explorer.
Using files edited in Git-Hub I noticed that using the Commonmark dialect I can render the tables correctly but not the notes.
Using the DaringFireball dialect the tables are no longer rendered correctly but the notes are correct.
Is it not possible to use a "mix" of the two dialects to obtain the same rendering that is obtained in Git-Hub?
Here an example with CommonMark:
Here an example with DaringFireball:
thank you.
Carlo
Create DaringFireball dialect:
TMarkdownProcessor.createDialect(mdDaringFireball)
Add string:
<file:c:\users>
or even shorter:
<\u
Result: infinite loop in this place:
class function TUtils.readUntil(out_: TStringBuilder; s: String; start: integer; cend: TSysCharSet): integer;
...
position := escape(out_, s[1 + position + 1], position) //<--- always returned the same position
Hey Graham – great job, thank you very very much.
So I can get a quick (and convenient) overview of the capabilities of the converter, I created myself a simple VCL with Delphi Tokyo (should be backwards compatible). Nothing in compare to your work but if you want you may add it as a demo. There are no dependencies to any libs etc. and a form transports (in my opition) more impressive the capagilites (and few missing) of the processor.
For those interested in: ZIP includes all required current files of Grahams project, compiles "out of the box": Markdown-VCL-Test.zip
Copy output from "memo2" to a html highlighting editor for better readable result (which is nicely compressed)
Planning you add ``` code support?
Temprary I add this, but lost formatting on pre code...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.