List for cgit developers and users
 help / color / mirror / Atom feed
* Table of Contents links using the format #link are not followed
@ 2018-07-06  9:56 actionmystique
  2018-07-13 16:14 ` list
  2018-07-13 19:48 ` [PATCH 1/1] filters: generate anchor links from markdown list
  0 siblings, 2 replies; 10+ messages in thread
From: actionmystique @ 2018-07-06  9:56 UTC (permalink / raw)


Ubuntu 18.10
cgit commit 22583c4
git 2.18.0-1

For instance, the following table of contents successfully tested on gitlab
is useless on cgit:
## Table of Contents

  + [Drive Repository Contents](#drive-repository-contents)
  + [Features](#features)
...

## Drive Repository Contents

...

## Features

Clicking on one of the table of contents link should redirect the user to
the corresponding paragraph, but it does not.
Either I'm missing something, or that feature is not implemented (yet?), or
there is some kind of issue.

-- 
Jean-Christophe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20180706/66ae1eea/attachment.html>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Table of Contents links using the format #link are not followed
  2018-07-06  9:56 Table of Contents links using the format #link are not followed actionmystique
@ 2018-07-13 16:14 ` list
  2018-07-13 16:39   ` 
  2018-07-13 19:48 ` [PATCH 1/1] filters: generate anchor links from markdown list
  1 sibling, 1 reply; 10+ messages in thread
From: list @ 2018-07-13 16:14 UTC (permalink / raw)


jean-christophe manciot <actionmystique at gmail.com> on Fri, 2018/07/06 11:56:
> Ubuntu 18.10
> cgit commit 22583c4
> git 2.18.0-1
> 
> For instance, the following table of contents successfully tested on gitlab
> is useless on cgit:
> ## Table of Contents
> 
>   + [Drive Repository Contents](#drive-repository-contents)
>   + [Features](#features)
> ...
> 
> ## Drive Repository Contents
> 
> ...
> 
> ## Features
> 
> Clicking on one of the table of contents link should redirect the user to
> the corresponding paragraph, but it does not.
> Either I'm missing something, or that feature is not implemented (yet?), or
> there is some kind of issue.

The links are ok, but python-markdown does not add the anchors in links
(a-tags). Anybody familiar with python-markdown can tell if that can be
changed?
-- 
main(a){char*c=/*    Schoene Gruesse                         */"B?IJj;MEH"
"CX:;",b;for(a/*    Best regards             my address:    */=0;b=c[a++];)
putchar(b-1/(/*    Chris            cc -ox -xc - && ./x    */b/42*2-3)*42);}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20180713/7702327e/attachment.asc>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Table of Contents links using the format #link are not followed
  2018-07-13 16:14 ` list
@ 2018-07-13 16:39   ` 
  0 siblings, 0 replies; 10+ messages in thread
From:  @ 2018-07-13 16:39 UTC (permalink / raw)


On 13/07/18 18:14, Christian Hesse wrote:
> jean-christophe manciot <actionmystique at gmail.com> on Fri, 2018/07/06 11:56:
>> Ubuntu 18.10
>> cgit commit 22583c4
>> git 2.18.0-1
>>
>> For instance, the following table of contents successfully tested on gitlab
>> is useless on cgit:
>> ## Table of Contents
>>
>>   + [Drive Repository Contents](#drive-repository-contents)
>>   + [Features](#features)
>> ...
>>
>> ## Drive Repository Contents
>>
>> ...
>>
>> ## Features
>>
>> Clicking on one of the table of contents link should redirect the user to
>> the corresponding paragraph, but it does not.
>> Either I'm missing something, or that feature is not implemented (yet?), or
>> there is some kind of issue.
> 
> The links are ok, but python-markdown does not add the anchors in links
> (a-tags). Anybody familiar with python-markdown can tell if that can be
> changed?
> 

There is an extension for python-markdown that does this, it is also
able to produce a table of contents dynamically:

https://python-markdown.github.io/extensions/toc/

Cheers,
-- 
Jan
______________________________________________________
   /\  # PGP: 362056ADA8F2F4E421565EF87F4A448FE68F329D
  /__\  # https://neuromancer.sk
 /\  /\  # Eastern Seaboard Phishing Authority
/__\/__\  #



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20180713/5e83fae5/attachment.asc>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/1] filters: generate anchor links from markdown
  2018-07-06  9:56 Table of Contents links using the format #link are not followed actionmystique
  2018-07-13 16:14 ` list
@ 2018-07-13 19:48 ` list
  2018-08-25  9:45   ` john
  1 sibling, 1 reply; 10+ messages in thread
From: list @ 2018-07-13 19:48 UTC (permalink / raw)


From: Christian Hesse <mail at eworm.de>

This makes the markdown filter generate anchor links for headings.

Signed-off-by: Christian Hesse <mail at eworm.de>
---
 filters/html-converters/md2html | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html
index ebf3856..dc20f42 100755
--- a/filters/html-converters/md2html
+++ b/filters/html-converters/md2html
@@ -3,6 +3,7 @@ import markdown
 import sys
 import io
 from pygments.formatters import HtmlFormatter
+from markdown.extensions.toc import TocExtension
 sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
 sys.stdout.write('''
@@ -48,10 +49,14 @@ sys.stdout.write('''
     line-height: 1;
     padding-left: 0;
     margin-left: -22px;
-    top: 15%}
+    top: 15%;
+}
 .markdown-body h1:hover a.anchor .mini-icon-link, .markdown-body h2:hover a.anchor .mini-icon-link, .markdown-body h3:hover a.anchor .mini-icon-link, .markdown-body h4:hover a.anchor .mini-icon-link, .markdown-body h5:hover a.anchor .mini-icon-link, .markdown-body h6:hover a.anchor .mini-icon-link {
     display: inline-block;
 }
+div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div#cgit .markdown-body h3 a.toclink, div#cgit .markdown-body h4 a.toclink, div#cgit .markdown-body h5 a.toclink, div#cgit .markdown-body h6 a.toclink {
+    color: black;
+}
 .markdown-body h1 tt, .markdown-body h1 code, .markdown-body h2 tt, .markdown-body h2 code, .markdown-body h3 tt, .markdown-body h3 code, .markdown-body h4 tt, .markdown-body h4 code, .markdown-body h5 tt, .markdown-body h5 code, .markdown-body h6 tt, .markdown-body h6 code {
     font-size: inherit;
 }
@@ -290,5 +295,13 @@ sys.stdout.write('''
 sys.stdout.write("<div class='markdown-body'>")
 sys.stdout.flush()
 # Note: you may want to run this through bleach for sanitization
-markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}})
+markdown.markdownFromFile(
+	output_format="html5",
+	extensions=[
+		"markdown.extensions.fenced_code",
+		"markdown.extensions.codehilite",
+		"markdown.extensions.tables",
+		TocExtension(anchorlink=True)],
+	extension_configs={
+		"markdown.extensions.codehilite":{"css_class":"highlight"}})
 sys.stdout.write("</div>")


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/1] filters: generate anchor links from markdown
  2018-07-13 19:48 ` [PATCH 1/1] filters: generate anchor links from markdown list
@ 2018-08-25  9:45   ` john
  2018-08-25 12:02     ` list
  0 siblings, 1 reply; 10+ messages in thread
From: john @ 2018-08-25  9:45 UTC (permalink / raw)


On Fri, Jul 13, 2018 at 09:48:27PM +0200, Christian Hesse wrote:
> From: Christian Hesse <mail at eworm.de>
> 
> This makes the markdown filter generate anchor links for headings.
> 
> Signed-off-by: Christian Hesse <mail at eworm.de>
> ---
>  filters/html-converters/md2html | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/filters/html-converters/md2html b/filters/html-converters/md2html
> index ebf3856..dc20f42 100755
> --- a/filters/html-converters/md2html
> +++ b/filters/html-converters/md2html
> @@ -3,6 +3,7 @@ import markdown
>  import sys
>  import io
>  from pygments.formatters import HtmlFormatter
> +from markdown.extensions.toc import TocExtension

Does this ship as part of python-markdown, or is it an additional
dependency?

>  sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
>  sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
>  sys.stdout.write('''
> @@ -48,10 +49,14 @@ sys.stdout.write('''
>      line-height: 1;
>      padding-left: 0;
>      margin-left: -22px;
> -    top: 15%}
> +    top: 15%;
> +}
>  .markdown-body h1:hover a.anchor .mini-icon-link, .markdown-body h2:hover a.anchor .mini-icon-link, .markdown-body h3:hover a.anchor .mini-icon-link, .markdown-body h4:hover a.anchor .mini-icon-link, .markdown-body h5:hover a.anchor .mini-icon-link, .markdown-body h6:hover a.anchor .mini-icon-link {
>      display: inline-block;
>  }
> +div#cgit .markdown-body h1 a.toclink, div#cgit .markdown-body h2 a.toclink, div#cgit .markdown-body h3 a.toclink, div#cgit .markdown-body h4 a.toclink, div#cgit .markdown-body h5 a.toclink, div#cgit .markdown-body h6 a.toclink {
> +    color: black;
> +}
>  .markdown-body h1 tt, .markdown-body h1 code, .markdown-body h2 tt, .markdown-body h2 code, .markdown-body h3 tt, .markdown-body h3 code, .markdown-body h4 tt, .markdown-body h4 code, .markdown-body h5 tt, .markdown-body h5 code, .markdown-body h6 tt, .markdown-body h6 code {
>      font-size: inherit;
>  }
> @@ -290,5 +295,13 @@ sys.stdout.write('''
>  sys.stdout.write("<div class='markdown-body'>")
>  sys.stdout.flush()
>  # Note: you may want to run this through bleach for sanitization
> -markdown.markdownFromFile(output_format="html5", extensions=["markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}})
> +markdown.markdownFromFile(
> +	output_format="html5",
> +	extensions=[
> +		"markdown.extensions.fenced_code",
> +		"markdown.extensions.codehilite",
> +		"markdown.extensions.tables",
> +		TocExtension(anchorlink=True)],
> +	extension_configs={
> +		"markdown.extensions.codehilite":{"css_class":"highlight"}})
>  sys.stdout.write("</div>")
> _______________________________________________
> CGit mailing list
> CGit at lists.zx2c4.com
> https://lists.zx2c4.com/mailman/listinfo/cgit


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/1] filters: generate anchor links from markdown
  2018-08-25  9:45   ` john
@ 2018-08-25 12:02     ` list
  2018-08-25 17:11       ` Jason
  0 siblings, 1 reply; 10+ messages in thread
From: list @ 2018-08-25 12:02 UTC (permalink / raw)


John Keeping <john at keeping.me.uk> on Sat, 2018/08/25 10:45:
> > diff --git a/filters/html-converters/md2html
> > b/filters/html-converters/md2html index ebf3856..dc20f42 100755
> > --- a/filters/html-converters/md2html
> > +++ b/filters/html-converters/md2html
> > @@ -3,6 +3,7 @@ import markdown
> >  import sys
> >  import io
> >  from pygments.formatters import HtmlFormatter
> > +from markdown.extensions.toc import TocExtension  
> 
> Does this ship as part of python-markdown, or is it an additional
> dependency?

Ships with python-markdown, at least I did not install anything on top.
-- 
main(a){char*c=/*    Schoene Gruesse                         */"B?IJj;MEH"
"CX:;",b;for(a/*    Best regards             my address:    */=0;b=c[a++];)
putchar(b-1/(/*    Chris            cc -ox -xc - && ./x    */b/42*2-3)*42);}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20180825/973c1541/attachment.asc>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/1] filters: generate anchor links from markdown
  2018-08-25 12:02     ` list
@ 2018-08-25 17:11       ` Jason
  2018-08-25 17:47         ` john
  0 siblings, 1 reply; 10+ messages in thread
From: Jason @ 2018-08-25 17:11 UTC (permalink / raw)


The effect is just anchor links, but it doesn't add an actual ToC, right?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/1] filters: generate anchor links from markdown
  2018-08-25 17:11       ` Jason
@ 2018-08-25 17:47         ` john
  2018-08-26  0:01           ` Jason
  0 siblings, 1 reply; 10+ messages in thread
From: john @ 2018-08-25 17:47 UTC (permalink / raw)


On Sat, Aug 25, 2018 at 11:11:39AM -0600, Jason A. Donenfeld wrote:
> The effect is just anchor links, but it doesn't add an actual ToC, right?

From the docs [0], it looks like it will add an actual ToC if you have a
placeholder in the document to request one.  But if you don't have that,
then it just generates anchors.

[0] https://python-markdown.github.io/extensions/toc/


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/1] filters: generate anchor links from markdown
  2018-08-25 17:47         ` john
@ 2018-08-26  0:01           ` Jason
  0 siblings, 0 replies; 10+ messages in thread
From: Jason @ 2018-08-26  0:01 UTC (permalink / raw)


Sounds pretty useful and hard to see downsides, then. Feel free to
queue this up in a for-jason.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Table of Contents links using the format #link are not followed
@ 2018-08-25  7:39 actionmystique
  0 siblings, 0 replies; 10+ messages in thread
From: actionmystique @ 2018-08-25  7:39 UTC (permalink / raw)


Christian Hesse (list at eworm.de) has brilliantly added this feature with the
patch available here
<https://git.zx2c4.com/cgit/diff/filters/html-converters/md2html?h=ch/anchorlinks&id=42e70dcbe84e128ba23a25918e3d5d9aac656dc6>
.
It allows you to:
- add your own static table of contents and the links now point to the
right paragraph
- or add a [TOC] marker anywhere in the markdown file and let cgit
dynamically build your table of contents

I was able to test the about link with a toc having up to 5 levels of
indentation, which is much more than Gitlab is able to do (2).

Very nice ;-)

N.B: I have just realized that a copy of this message has been originally &
mistakenly sent as an answer to another thread. Sorry guys.

-- 
Jean-Christophe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20180825/2b63c6b3/attachment.html>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-08-26  0:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-06  9:56 Table of Contents links using the format #link are not followed actionmystique
2018-07-13 16:14 ` list
2018-07-13 16:39   ` 
2018-07-13 19:48 ` [PATCH 1/1] filters: generate anchor links from markdown list
2018-08-25  9:45   ` john
2018-08-25 12:02     ` list
2018-08-25 17:11       ` Jason
2018-08-25 17:47         ` john
2018-08-26  0:01           ` Jason
2018-08-25  7:39 Table of Contents links using the format #link are not followed actionmystique

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).