Skip to content

Commit

Permalink
Merge pull request #133 from HL7/gg-process-markdown
Browse files Browse the repository at this point in the history
Issue #132 - process markdown in lists
  • Loading branch information
grahamegrieve authored Jul 18, 2020
2 parents a12714f + af78148 commit f2b3f4d
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 49 deletions.
17 changes: 16 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
* fix problem with narrative being generated after validation for Canonical Resources
* Package subsystem: fix QICore loading with a hack to work around past mistake
* X-Version support: fix problem converting DataRequirements across versions
* Snapshot Generator: fix bug assigning min=0 to slices by default
* Validator: Add support for conformsTo in invariants on elements
* Validator: Handle weird ege case for fixedReference
* Validator: Improved checking of narrative (including picking up empty narrative)
* Cql Subsystem: update to 1.50
* Renderer: fix problem with narrative being generated after validation for Canonical Resources
* Renderer: fix rendering of must-support view
* Renderer: fix rendering of multiple type profiles
* Renderer: fix bundle rendering
* Renderer: process markdown when generating lists of resources
* Renderer: Fix rendering of contained resources (outside Canonical Resources)
* qa.html: error if mentioning validator.pack
* qa.html: decode URLs before checking them
* qa.html: fix check for current version number
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public Boolean getHl7State() {
private boolean missingPublishBox;
private List<String> missingPublishBoxList = new ArrayList<>();
private Set<String> exceptions = new HashSet<>();
private boolean referencesValidatorPack;

public HTLMLInspector(String rootFolder, List<SpecMapManager> specs, ILoggingService log, String canonical, String packageId) {
this.rootFolder = rootFolder.replace("/", File.separator);
Expand Down Expand Up @@ -256,10 +257,15 @@ public List<ValidationMessage> check(String statusText) throws IOException {
first = false;
}
}
if (lf.getXhtml() != null)
if (lf.getXhtml() != null) {
referencesValidatorPack = false;
if (checkLinks(s, "", lf.getXhtml(), null, messages, false) != NodeChangeType.NONE) { // returns true if changed
saveFile(lf);
}
if (referencesValidatorPack) {
messages.add(new ValidationMessage(Source.Publisher, IssueType.BUSINESSRULE, s, "The html source references validator.pack which is deprecated. Change the IG to describe the use of the package system instead", IssueSeverity.ERROR));
}
}
}

log.logDebugMessage(LogCategory.HTML, "Checking Other Links");
Expand Down Expand Up @@ -457,18 +463,28 @@ private void listTargets(XhtmlNode x, Set<String> targets) {

private NodeChangeType checkLinks(String s, String path, XhtmlNode x, String uuid, List<ValidationMessage> messages, boolean inPre) throws IOException {
boolean changed = false;
if (x.getName() != null)
if (x.getName() != null) {
path = path + "/"+ x.getName();
if ("title".equals(x.getName()) && Utilities.noString(x.allText()))
} else {
if (x.getContent() != null && x.getContent().contains("validator.pack")) {
referencesValidatorPack = true;
}
}
if ("title".equals(x.getName()) && Utilities.noString(x.allText())) {
x.addText("?html-link?");
if ("a".equals(x.getName()) && x.hasAttribute("href"))
}
if ("a".equals(x.getName()) && x.hasAttribute("href")) {
changed = checkResolveLink(s, x.getLocation(), path, x.getAttribute("href"), x.allText(), messages, uuid);
if ("img".equals(x.getName()) && x.hasAttribute("src"))
}
if ("img".equals(x.getName()) && x.hasAttribute("src")) {
changed = checkResolveImageLink(s, x.getLocation(), path, x.getAttribute("src"), messages, uuid) || changed;
if ("link".equals(x.getName()))
}
if ("link".equals(x.getName())) {
changed = checkLinkElement(s, x.getLocation(), path, x.getAttribute("href"), messages, uuid) || changed;
if ("script".equals(x.getName()))
}
if ("script".equals(x.getName())) {
checkScriptElement(s, x.getLocation(), path, x, messages);
}
String nuid = UUID.randomUUID().toString().toLowerCase();
boolean nchanged = false;
boolean nSelfChanged = false;
Expand Down Expand Up @@ -510,13 +526,17 @@ private boolean checkLinkElement(String filename, Location loc, String path, Str

private boolean checkResolveLink(String filename, Location loc, String path, String ref, String text, List<ValidationMessage> messages, String uuid) throws IOException {
links++;
String rref = ref;
String rref = Utilities.URLDecode(ref);
if ((rref.startsWith("http:") || rref.startsWith("https:") ) && (rref.endsWith(".sch") || rref.endsWith(".xsd") || rref.endsWith(".shex"))) { // work around for the fact that spec.internals does not track all these minor things
rref = Utilities.changeFileExt(ref, ".html");
}
if (rref.startsWith("./"))
if (rref.startsWith("./")) {
rref = rref.substring(2);
}

if (rref.contains("validator.pack")) {
referencesValidatorPack = true;
}
String tgtList = "";
boolean resolved = Utilities.existsInList(ref, "qa.html", "http://hl7.org/fhir", "http://hl7.org", "http://www.hl7.org", "http://hl7.org/fhir/search.cfm") ||
ref.startsWith("http://gforge.hl7.org/gf/project/fhir/tracker/") || ref.startsWith("mailto:") || ref.startsWith("javascript:");
Expand All @@ -538,8 +558,9 @@ private boolean checkResolveLink(String filename, Location loc, String path, Str

if (!resolved) {
String fref = Utilities.path(Utilities.getDirectoryForFile(filename), ref);
if (fref.equals(Utilities.path(rootFolder, "qa.html")))
if (fref.equals(Utilities.path(rootFolder, "qa.html"))) {
resolved = true;
}
}
// special case end-points that are always valid:
if (!resolved)
Expand All @@ -552,8 +573,9 @@ private boolean checkResolveLink(String filename, Location loc, String path, Str
resolved = true;
if (specs != null) {
for (SpecMapManager spec : specs) {
if (rref.startsWith(spec.getBase()))
if (rref.startsWith(spec.getBase())) {
resolved = false;
}
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,9 @@ else if (vsCache == null) {
if (sourceIg.hasLicense())
license = sourceIg.getLicense().toCode();
npmName = sourceIg.getPackageId();
if (Utilities.noString(npmName)) {
throw new Error("No packageId provided in the implementation guide resource - cannot build this IG");
}
appendTrailingSlashInDataFile = true;
includeHeadings = template.getIncludeHeadings();
igArtifactsPage = template.getIGArtifactsPage();
Expand Down Expand Up @@ -2594,7 +2597,8 @@ private void loadIg(ImplementationGuideDependsOnComponent dep, int index) throws
}
}
String webref = pi.getWebLocation();

webref = fixPackageUrl(webref);

SpecMapManager igm = pi.hasFile("other", "spec.internals") ? new SpecMapManager( TextFile.streamToBytes(pi.load("other", "spec.internals")), pi.fhirVersion()) : SpecMapManager.createForSimplifier(pi);
igm.setName(name);
igm.setBase(canonical);
Expand Down Expand Up @@ -2748,6 +2752,7 @@ private void loadIg(JsonObject dep) throws Exception {
String location = dep.has("location") ? dep.get("location").getAsString() : "";
if (location.startsWith(".."))
webref = location;
webref = fixPackageUrl(webref);

String ver = pi.fhirVersion();
SpecMapManager igm = new SpecMapManager(TextFile.streamToBytes(pi.load("other", "spec.internals")), ver);
Expand All @@ -2764,6 +2769,14 @@ private void loadIg(JsonObject dep) throws Exception {
}


// workaround for past publishing problem
private String fixPackageUrl(String webref) {
if (webref.equals("file://C:\\GitHub\\hl7.fhir.us.qicore#4.0.0\\output")) {
return "http://hl7.org/fhir/us/qicore/STU4";
}
return webref;
}

private NpmPackage resolveDependency(String canonical, String packageId, String igver) throws Exception {
if (packageId != null)
return pcm.loadPackage(packageId, igver);
Expand Down Expand Up @@ -6147,10 +6160,7 @@ private void generateLogicals() throws Exception {
fragment("table-logicals-mm", tableMM.toString(), otherFilesRun);
}

private void genEntryItem(
StringBuilder list, StringBuilder lists, StringBuilder table,
StringBuilder listMM, StringBuilder listsMM, StringBuilder tableMM,
FetchedFile f, FetchedResource r, String name, String prefixType) throws Exception {
private void genEntryItem(StringBuilder list, StringBuilder lists, StringBuilder table, StringBuilder listMM, StringBuilder listsMM, StringBuilder tableMM, FetchedFile f, FetchedResource r, String name, String prefixType) throws Exception {
String ref = igpkp.doReplacements(igpkp.getLinkFor(r, false), r, null, null);
if (Utilities.noString(ref))
throw new Exception("No reference found for "+r.getId());
Expand All @@ -6159,18 +6169,30 @@ private void genEntryItem(
ref = ref.substring(0, ref.lastIndexOf("."))+"."+prefixType+ref.substring(ref.lastIndexOf("."));
else
ref = ref+"."+prefixType;
PrimitiveType desc = new StringType(r.getTitle());
if (!r.hasTitle())
desc = new StringType(f.getTitle());
String desc = r.getTitle();
String descSrc = "Resource Title";
if (!r.hasTitle()) {
desc = f.getTitle();
descSrc = "File Title";
}
if (r.getResource() != null && r.getResource() instanceof CanonicalResource) {
name = ((CanonicalResource) r.getResource()).present();
desc = getDesc((CanonicalResource) r.getResource(), desc);
String d = getDesc((CanonicalResource) r.getResource()).asStringValue();
if (d != null) {
desc = markdownEngine.process(d, descSrc);
descSrc = "Canonical Resource";
}
} else if (r.getElement() != null && r.getElement().hasChild("description")) {
desc = new StringType(r.getElement().getChildValue("description"));
String d = new StringType(r.getElement().getChildValue("description")).asStringValue();
if (d != null) {
desc = markdownEngine.process(d, descSrc);
// new BaseRenderer(context, null, igpkp, specMaps, markdownEngine, packge, rc).processMarkdown("description", desc )
descSrc = "Canonical Resource Source";
}
}
list.append(" <li><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a> "+Utilities.escapeXml(desc.asStringValue())+"</li>\r\n");
list.append(" <li><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a> "+desc+"</li>\r\n");
lists.append(" <li><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a></li>\r\n");
table.append(" <tr><td><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a> </td><td>"+new BaseRenderer(context, null, igpkp, specMaps, markdownEngine, packge, rc).processMarkdown("description", desc )+"</td></tr>\r\n");
table.append(" <tr><td><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a> </td><td>"+desc+"</td></tr>\r\n");

if (listMM != null) {
String mm = "";
Expand All @@ -6181,9 +6203,9 @@ private void genEntryItem(
mm = " <a class=\"fmm\" href=\"http://hl7.org/fhir/versions.html#maturity\" title=\"Maturity Level\">"+fmm+"</a>";
}
}
listMM.append(" <li><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a>"+mm+" "+Utilities.escapeXml(desc.asStringValue())+"</li>\r\n");
listMM.append(" <li><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a>"+mm+" "+desc+"</li>\r\n");
listsMM.append(" <li><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a>"+mm+"</li>\r\n");
tableMM.append(" <tr><td><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a> </td><td>"+new BaseRenderer(context, null, igpkp, specMaps, markdownEngine, packge, rc).processMarkdown("description", desc )+"</td><td>"+mm+"</td></tr>\r\n");
tableMM.append(" <tr><td><a href=\""+ref+"\">"+Utilities.escapeXml(name)+"</a> </td><td>"+desc+"</td><td>"+mm+"</td></tr>\r\n");
}
}

Expand Down Expand Up @@ -6263,10 +6285,8 @@ public void genResourceReferencesList(String rt, List<Item> items, String ext) t
}

@SuppressWarnings("rawtypes")
private PrimitiveType getDesc(CanonicalResource r, PrimitiveType desc) {
if (r.hasDescription())
return r.getDescriptionElement();
return desc;
private PrimitiveType getDesc(CanonicalResource r) {
return r.getDescriptionElement();
}

private Number getErrorCount() {
Expand Down Expand Up @@ -6794,7 +6814,7 @@ private void makeTemplatesContained(FetchedFile f, FetchedResource r, Resource r
for (String templateName : extraTemplates.keySet()) {
String output = igpkp.getProperty(r, templateName);
if (output == null)
output = r.getElement().fhirType()+"-"+r.getId()+"-"+templateName+".html";
output = r.getElement().fhirType()+"-"+r.getId()+"_"+res.getId()+"-"+templateName+".html";
genWrapperContained(null, r, res, igpkp.getPropertyContained(r, "template-"+templateName, res), output, f.getOutputNames(), vars, null, templateName, prefixForContained);
}
}
Expand Down Expand Up @@ -7927,8 +7947,6 @@ public String getJekyllCommand() {
return this.jekyllCommand;
}



public static String determineActualIG(String ig, IGBuildMode mode) throws Exception {
File f = new File(ig);
if (!f.exists() && mode == IGBuildMode.AUTOBUILD) {
Expand Down
Loading

0 comments on commit f2b3f4d

Please sign in to comment.