Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change from spans to divs #122

Merged
merged 9 commits into from
Dec 4, 2017
Merged

Change from spans to divs #122

merged 9 commits into from
Dec 4, 2017

Conversation

goneall
Copy link
Member

@goneall goneall commented Nov 28, 2017

Change from spans to divs for the HTML representation of optional and variable license text.

Address issue #121

Signed-off-by: Gary O'Neall gary@sourceauditor.com

… variable license text

Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
@@ -98,17 +98,17 @@ private void removeEndParagraphTag() {
*/
public static String formatReplaceabledHTML(String text, String id) {
StringBuilder sb = new StringBuilder();
sb.append("\n<span ");
sb.append("\n<div ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going too far in the other direction :p. In #121, I'm advocating <var> (or <span>) when we're wrapping phrasing content, and <div> when we're wrapping flow content. I don't think there's a single element that will cover both cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is used for the old license spreadsheet and license text. I'll change this back to spans since the old format will not include any phrasing content.

@goneall
Copy link
Member Author

goneall commented Nov 29, 2017

I don't think there's a single element that will cover both cases.

It would be design change with some effort to detect if there is phrasing content. The div's seem to render correctly if I use the inline style.

@wking what is the effect of wrapping non-phrasing content with an inline <div>?

@wking
Copy link
Contributor

wking commented Nov 29, 2017 via email

@goneall
Copy link
Member Author

goneall commented Nov 29, 2017

So I think we want to be using var whenever possible, and only falling
back to div when the element contains flow content. That way we
aren't changing the content type with our wrapping.

Hmmm - looks like something I need to fix. May take a couple days since this will require some additional parsing.

@wking
Copy link
Contributor

wking commented Nov 30, 2017 via email

Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
@goneall
Copy link
Member Author

goneall commented Nov 30, 2017

Added a commit to conditionally use a var tag if there is no phrasing-content in the element.

Attached is the generated ISC license.

The var and optional text passes the w3c validator and it seems to render OK on Chrome.
ISC.html.txt

if (id != null && !id.trim().isEmpty()) {
sb.append("id=\"");
sb.append(escapeIdString(id));
sb.append("\" ");
}
sb.append("class=\"");
sb.append(REPLACEABLE_LICENSE_TEXT_CLASS);
sb.append("\">");
sb.append("\" style=\"display: inline\">");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With <var> for phrasing content, I don't think you need this style anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be needed for the div's?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be needed for the div's?

I don't think so, because all the inline cases will now be var. This styling was a workaround for a case (inline divs) that should no longer happen.

…ng element

Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
@goneall
Copy link
Member Author

goneall commented Nov 30, 2017

Check the latest commit - see if that fixes it. The LICENSEXML_ELEMENT... constants are defined in SpdxRdfConstants.java

These constants refer to the input license XML elements (not the output HTML elements).

@goneall
Copy link
Member Author

goneall commented Nov 30, 2017

How about alt's or optionals embedded in other optionals? Should those be wrapped in a div? Otherwise we would have <var ...> top level optional <var ...>nested optional</var> ... </var>

@goneall
Copy link
Member Author

goneall commented Nov 30, 2017

In looking at the W3C validator link above, I noticed the following error:

From line 170, column 1; to line 170, column 5
     <br>↩</br>Copyri

<p>Copyright (c) ↩
<var class="replacable-license-text">2004-2010 by Internet Systems Consortium, Inc. (&quot;ISC&quot;)↩
        <br>↩
</br>Copyright (c) 1995-2003 by Internet Software Consortium</var>↩

Is this anything to worry about?

…nges to the HtmlTemplateOutputHandler - back to spans

Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
@wking
Copy link
Contributor

wking commented Nov 30, 2017

Otherwise we would have <var ...> top level optional <var ...>nested optional</var> ... </var>

When none of the content contains a p or list element (at any depth, not just as immediate children), then I think we should be using <var>. I have no problem with the nested-<var> in your example (although see my comments about styling them).

From line 170, column 1; to line 170, column 5
    <br>↩</br>Copyri

If you mean the “Error: End tag br.”, yes, that is something to worry about. From the HTML 5 spec for br:

Tag omission in text/html:
No end tag

And we're serving that content as HTML, not XHTML:

$ curl -sI https://spdx.org/licenses/preview/ISC.html | grep Content-Type
Content-Type: text/html; charset=UTF-8

But that's orthogonal to this issue.

@@ -117,6 +117,12 @@
EXAMPLE_UNPROCESSED_TAGS.add(LICENSEXML_ELEMENT_BULLET);
}

static HashSet<String> PHRASING_ELEMENTS = new HashSet<String>();
static {
PHRASING_ELEMENTS.add(LICENSEXML_ELEMENT_LIST);
Copy link
Contributor

@wking wking Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHRASING_ELEMENTS still needs to be renamed to FLOW_CONTENT_ELEMENTS (or similar).

sb.append(HtmlTemplateOutputHandler.OPTIONAL_LICENSE_TEXT_CLASS);
sb.append("\">");
sb.append(childSb.toString());
sb.append("</span>");
if (includesPhrasing(element)) {
sb.append("</div>");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a bit DRYer and slightly more performant if you had a single:

if (includesFlowContent(element)) {
  tag = "div";
} else {
  tag = "var";
}

and then used that tag variable for both the start and end tag.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree - I was just being lazy ;) I'll update the PR

Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
* @param element parent element
* @return true if the element includes any phrasing content per https://www.w3.org/TR/2014/REC-html5-20141028/dom.html#phrasing-content-1
*/
private static boolean includesPhrasing(Element element) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be includesFlowControl, and you'll want to update its comment, callers, etc. This is bubbling up the FLOW_CONTROL_ELEMENTS rename to use the correct name throughout the new code.

* @return true if the element includes any phrasing content per https://www.w3.org/TR/2014/REC-html5-20141028/dom.html#phrasing-content-1
*/
private static boolean includesPhrasing(Element element) {
NodeList children = element.getChildNodes();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getChildNodes seems to only return immediate children. We want something that iterates over all descendants to catch <optional>…<optional><p>…</p></optional></optional>. A quick grep through the docs didn't turn up anything that sounded right, so we may need to implement this locally (or call includesFlowControl recursively?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already does a recursive search (line 355)

Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
@goneall
Copy link
Member Author

goneall commented Dec 1, 2017

if you mean the “Error: End tag br.”, yes, that is something to worry about.

Just pushed a fix for the end tag br.

@goneall
Copy link
Member Author

goneall commented Dec 1, 2017

And we're serving that content as HTML, not XHTML

Is this an issue with the templates in the resources folder (e.g.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
)? If so, feel free to submit a PR to fix.

Signed-off-by: Gary O'Neall <gary@sourceauditor.com>
@goneall
Copy link
Member Author

goneall commented Dec 4, 2017

I believe all the comments have been resolved and a new issue was spun off to track the XHTML issue #123

@goneall goneall merged commit 9842022 into master Dec 4, 2017
@goneall goneall deleted the spantodiv branch December 4, 2017 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants