Last active
March 16, 2022 14:30
-
-
Save jurgenvinju/3bf96627573ed54b5b48071034323f61 to your computer and use it in GitHub Desktop.
Turn a block of hypothesis document annotations into a plaintext list of detailed comments for a peer review
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HypothesisToReview | |
import lang::html::IO; | |
import IO; | |
import List; | |
// this is a simple HTML scraper against an untyped HTML document model (`node`) | |
str detailedComments(loc hypothesisCards) { | |
content = readHTMLFile(annos); | |
review = ""; | |
for (/card:"li"(_,class="annotation-card") := content) { | |
if (/"blockquote"(["text"(str quote)]) := card) { | |
if (/"div"(["p"(["text"(str comment)])],class="annotation-card__text") := card) { | |
review += "\> <quote> | |
' <comment>\n\n"; | |
} | |
else { | |
review += "\> <quote> - highlighted\n\n"; | |
} | |
} | |
else { | |
throw "no quote? <card>"; | |
} | |
} | |
return review; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
"li"
and"div"
that do not have an ADT declaration./
operator allows us to skip all kinds of uninteresting structure and matchingclass
attributes using "keyword field matching" allows us to anchor where we want to find information again.+=
concatenates string templates lazily for maximal efficiency (it uses an internally balanced tree to avoid stack overflow)