Git Product home page Git Product logo

delphi-markdown's People

Contributors

grahamegrieve avatar xqueezeme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

delphi-markdown's Issues

Incorrect list convertion

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

  1. list

  2. with

  3. numbered items

Non-breaking space after emphasis delimiter seemingly breaks parsing.

Using the CommonMark engine. Where <&nbsp;> 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.

Input:

**First Line?**<&nbsp;>\
\
Second **Line**

Expected Output:

<p><strong>First Line?</strong><&nbsp;><br />
<br />
Second <strong>Line</strong>.</p>

Actual Output:

<p><strong>First Line?<strong><&nbsp;><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...

  • Removing the punctuation
  • Replacing the <&nbsp;> with a normal space
  • Replacing the <&nbsp;> with punctuation
  • Switching the punctuation and <&nbsp;> positions

...but none of those changes seemingly trigger the bug.

Space in local links breaks mardown parsing

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?

Different conversion from DaringFireball and Commonmark compared to Gith-Hub

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:
image
Here an example with DaringFireball:
image

thank you.
Carlo

line with open tag hangs

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;

Code ```

Planning you add ``` code support?
Temprary I add this, but lost formatting on pre code...

Remove the dependency on the LazUTF8 module

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;

Range check error

Try convert string with a lone bracket mark at the beginning of the line:

some text
<
other text

this raised Range Check exception

Getting the id for headings

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;

MarkDownTests.dproj issues

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:

  1. FastMM4 should be first in uses list.

  2. I don't know where to get TestInsight, so I commented out the lines in sourcecode. TESTINSIGHT variable is set in MarkDownTests.dproj

  3. exe file is compiled inside delphi-markdown\delphi\ dir, so I copied resources dir here.

  4. 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&ouml;&ouml; "f&ouml;&ouml;")
"

  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&auml;)
"

  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&ouml;&ouml; "f&ouml;&ouml;")
"

  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&auml;)
"

  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.

VCL Tester

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)

Infinite loop and out of memory error

  1. Create DaringFireball dialect:
    TMarkdownProcessor.createDialect(mdDaringFireball)

  2. Add string:

<file:c:\users>
or even shorter:
<\u

  1. Process mardown.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.