cmark

My personal build of CMark ✏️

Commit
2590e3b4448798db88f650a4fbc37cec3b741a4a
Parent
ace1b42818ebdbee46ca0153fb0b49e1494321e0
Author
John MacFarlane <jgm@berkeley.edu>
Date

Moved spec.html error checks into makespec.py.

Diffstat

2 files changed, 22 insertions, 8 deletions

Status File Name N° Changes Insertions Deletions
Modified Makefile 8 0 8
Modified makespec.py 22 22 0
diff --git a/Makefile b/Makefile
@@ -180,14 +180,6 @@ dingus: js/commonmark.js
 spec.md: $(SPEC)
 	python3 makespec.py markdown > $@
 
-spec: spec.html
-	@anchors=`perl -ne '@matches = / id="([^"]*)"/g; foreach $$match (@matches) { print "$$match\n"; }' $<`; \
-	links=`perl -ne '@matches = / href="#([^"]*)"/g; foreach $$match (@matches) { print "$$match\n"; }' $<`; \
-	for link in $$links; do \
-		[[ $$anchors =~ $$link ]] || \
-			 echo "Link to missing anchor #$$link"; \
-	done
-
 spec.html: spec.txt template.html ${PROG}
 	python3 makespec.py html > $@
 
diff --git a/makespec.py b/makespec.py
@@ -129,6 +129,28 @@ elif specformat == "html":
     if retcode == 0:
         result = re.sub(r'␣', '<span class="space"> </span>', result)
         sys.stdout.write(template.substitute(metadata, body=result))
+
+        # check for errors:
+        idents = []
+        for ident in re.findall(r'id="([^"]*)"', result):
+            if ident in idents:
+                sys.stderr.write("WARNING: duplicate identifier '" + ident +
+                                 "'\n")
+            else:
+                idents.append(ident)
+        for href in re.findall(r'href="#([^"]*)"', result):
+            if not (href in idents):
+                sys.stderr.write("WARNING: internal link with no anchor '" +
+                                 href + "'\n")
+        reftexts = []
+        for ref in refs:
+            ref = re.sub('].*',']',ref).upper()
+            if ref in reftexts:
+                sys.stderr.write("WARNING: duplicate reference link '" +
+                                 ref + "'\n")
+            else:
+                reftexts.append(ref)
+
     else:
         sys.stderr.write("Error converting markdown version of spec:\n")
         sys.stderr.write(err)