Skip to content

Commit 927af4b

Browse files
committed
Miscounting in case of markdown links
When we have simple input files like: ``` Chrome's trace viewer (Catapult) following the [instructions]( https://chromium.googlesource.com/catapult/+/refs/heads/master/tracing/docs/embedding-trace-viewer.md). This directory contains the helper files to embed Chrome's trace viewer. The current resources were generated/copied from [`Catapult@9508452e18f130c98499cb4c4f1e1efaedee8962` ]( https://chromium.googlesource.com/catapult/+/9508452e18f130c98499cb4c4f1e1efaedee8962). \aa11 ``` or ``` Add new exported module Text.Pandoc.Writers.AnnotatedTable [API change] (#6655, Christian Despres). This module (which should generally \bb3 ``` one gets (in the current master version, a5ac108): ``` .../aa.md:8: warning: Found unknown command '\aa11' .../bb.md:3: warning: Found unknown command '\bb4' ``` instead of ``` .../aa.md:11: warning: Found unknown command '\aa11' .../bb.md:4: warning: Found unknown command '\bb4' ``` this is due to the fact that the newlines inside the links are not taken into consideration during the conversion. We can add the extra newlines but have to do this inside the `<...>` as than they are handled correctly later on: - when adding them before the `<` doxygen sees a newline and will start a new paragraph starting with the link instead of keeping it in its place. - when adding them after the `>` we can get a warning about `warning: End of list marker found without any preceding list items` when after the closing `)` of the link there is directly a `.`
1 parent a5ac108 commit 927af4b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/markdown.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ int Markdown::processLink(const char *data,int,int size)
808808
}
809809
contentStart=i;
810810
int level=1;
811+
int nlTotal=0;
811812
int nl=0;
812813
// find the matching ]
813814
while (i<size)
@@ -831,6 +832,8 @@ int Markdown::processLink(const char *data,int,int size)
831832
}
832833
i++;
833834
}
835+
nlTotal += nl;
836+
nl = 0;
834837
if (i>=size) return 0; // premature end of comment -> no link
835838
contentEnd=i;
836839
convertStringFragment(content,data+contentStart,contentEnd-contentStart);
@@ -843,9 +846,12 @@ int Markdown::processLink(const char *data,int,int size)
843846
if (i<size && data[i]=='\n') // one newline allowed here
844847
{
845848
i++;
849+
nl++;
846850
// skip more whitespace
847851
while (i<size && data[i]==' ') i++;
848852
}
853+
nlTotal += nl;
854+
nl = 0;
849855

850856
bool explicitTitle=FALSE;
851857
if (i<size && data[i]=='(') // inline link
@@ -854,7 +860,6 @@ int Markdown::processLink(const char *data,int,int size)
854860
while (i<size && data[i]==' ') i++;
855861
if (i<size && data[i]=='<') i++;
856862
linkStart=i;
857-
nl=0;
858863
int braceCount=1;
859864
while (i<size && data[i]!='\'' && data[i]!='"' && braceCount>0)
860865
{
@@ -876,6 +881,8 @@ int Markdown::processLink(const char *data,int,int size)
876881
i++;
877882
}
878883
}
884+
nlTotal += nl;
885+
nl = 0;
879886
if (i>=size || data[i]=='\n') return 0;
880887
convertStringFragment(link,data+linkStart,i-linkStart);
881888
link = link.stripWhiteSpace();
@@ -985,6 +992,8 @@ int Markdown::processLink(const char *data,int,int size)
985992
{
986993
return 0;
987994
}
995+
nlTotal += nl;
996+
nl = 0;
988997
if (isToc) // special case for [TOC]
989998
{
990999
int toc_level = Config_getInt(TOC_INCLUDE_HEADINGS);
@@ -1066,6 +1075,7 @@ int Markdown::processLink(const char *data,int,int size)
10661075
m_out.addStr("<a href=\"");
10671076
m_out.addStr(link);
10681077
m_out.addStr("\"");
1078+
for (int i = 0; i < nlTotal; i++) m_out.addStr("\n");
10691079
if (!title.isEmpty())
10701080
{
10711081
m_out.addStr(" title=\"");

0 commit comments

Comments
 (0)