Browse Source

Added lua script from pandoc discussion to convert links to new tab in html

nitrocode 7 years ago
parent
commit
302905702a
2 changed files with 16 additions and 0 deletions
  1. 1 0
      Makefile
  2. 15 0
      pdc-links-target-blank.lua

+ 1 - 0
Makefile

@@ -22,6 +22,7 @@ html: init
 		FILE_NAME=`basename $$f | sed 's/.md//g'`; \
 		echo $$FILE_NAME.html; \
 		pandoc --standalone --include-in-header $(STYLES_DIR)/$(STYLE).css \
+			--lua-filter=pdc-links-target-blank.lua \
 			--from markdown --to html \
 			--output $(OUT_DIR)/$$FILE_NAME.html $$f; \
 	done

+ 15 - 0
pdc-links-target-blank.lua

@@ -0,0 +1,15 @@
+-- Add target="_blank" attributes to all http links in a Pandoc document
+
+local function add_target_blank (link)
+    if string.match(link.target, '^http') then  -- here .target == href attribute
+        link.attributes.target = '_blank'       -- here .target == traget attribute
+    end
+    return link
+end
+
+-- remove lines 4 and 6 to add target="_blank" to all links, not just http(s)
+
+return {
+    { Link = add_target_blank }
+}
+