List for cgit developers and users
 help / color / mirror / Atom feed
From: list at eworm.de (Christian Hesse)
Subject: [PATCH 1/1] filters: generate anchor links from markdown
Date: Fri, 13 Jul 2018 21:48:27 +0200	[thread overview]
Message-ID: <20180713194827.12799-1-list@eworm.de> (raw)
In-Reply-To: <CAKcFC3Y_vZ-mJAN2gGwPgjC6YYzhLbthCWK9D4=+1aqgjifAgA@mail.gmail.com>

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>")


  parent reply	other threads:[~2018-07-13 19:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` list [this message]
2018-08-25  9:45   ` [PATCH 1/1] filters: generate anchor links from markdown 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180713194827.12799-1-list@eworm.de \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).