-
Notifications
You must be signed in to change notification settings - Fork 133
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
Support context-aware includes for images and anchors #826
Conversation
@Chng-Zhi-Xuan there were some issues with the commit previously - i've updated and rebased. Please pull the changes again. Thanks! |
I will be testing in-depth more tomorrow due to time constraints. Not immediately after requesting for review from myself :P |
Do test with boilerplate files. |
A brief comment from a quick glance... commit 11bb1e8 seems to be doing two different things at the same time (adding test + pushing the parsing of img and anchors to a later stage), is it not possible to split it up? |
Oh no. One of the commits disappeared / got squashed together... I'll fix that up in a bit. Thanks for the heads up. Edit: It appears okay now. |
2e39f3f
to
40988ee
Compare
3313e79
to
3635062
Compare
test/functional/test_site/expected/sub_site/testReuse._include_.html
Outdated
Show resolved
Hide resolved
Thanks @yamgent. That was dangerous - I had thought that the relative URLs in the testReuse.include.html was something expected from the new behaviour. I've fixed the oversight. Now, included files (via panels) should be processed correctly too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit "Parser: Support context-aware includes"
This means that content in an included file must be valid wherever it is included from. For example, resource references need to be absolute paths, so that they remain valid wherever they are included from.
Um, the England here doesn't make sense? :P Are you trying to say that
paths need to be valid regardless of wherever it is included from?
I was trying to say something like if we have 2 files from different places, e.g. I've updated the commit message and fixed the {{hostBaseUrl}} bug. I still don't really like my commit message, but I can't find a clearer way to express the idea above^ |
I put in the example that you gave, and also invented the word "host file", see if that makes it clearer. The first two paragraphs are modified.
|
6f20e97
to
c9213fb
Compare
Yes! The use of "host file" made it much clearer. Thank you so much - I will adopt this commit message :D I've also attempted a fix for the Windows bug @Chng-Zhi-Xuan by forcing it to use posix notation. I've tested it on a Windows VM and it looks fine now. |
Thanks for reviewing @yamgent. Sorry I had to dismiss your review because I found an issue with authoringContents.md (and some CS2103T pages) that happened as a result of inline includes. I've taken a quick glance at the resulting CS2103T and TE3201 websites, they look more fine now :P I'll still need to update the documentation to reflect the change in our includes. Will do that tomorrow. |
Hi @sijie123 Thanks for updating the PR, and doing additional tests. It will be good to add a Just a minor QoL nit :P |
9597ebc
to
f108f1c
Compare
Finally! I think I'm done with everything I set out to do... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with panels and nested panels and seems fine so far 👍
Just a couple of comments, feel free to give your perspective if needed.
After our parser includes a file, its context is discarded. This means that in subsequent passes of parser, we do not know where the content has been included from, and included content is treated uniformly as if they were originally part of the host file. The path of the references in the included file may not resolve correctly if it belongs to a different directory from the host file. For example, if /a/b/c.md refers to a file in '../file.css', and /index.md is the host file that includes /a/b/c.md, then /index.md should resolve this path to '/a/b/file.css'. It cannot retain the original path '../file.css', as that will lead to the wrong css file. To support context-aware references, i.e. the included segments retain awareness of their original include locations, let's add a data-included-from meta whenever we include files. To maintain the existing behaviour and to prevent leaking file structure data, this meta tag is removed before we finish generating the final website.
MarkBind does not support relative references if they are written using Markdown syntax. The existing MarkBind parser only processes relative URLs once during the preprocess stage, during which Markdown code has not yet been transcribed into html. With context-based includes available in a previous commit, we can now store the context from which files are included from. We can then use this information to derive the absolute path of a resource referenced by an included file. Let's rewrite the support for relative URLs by processing all such relative URLs after the site is generated. This way, we can convert relative URLs in Markdown code to absolute URLs too. With this new method of processing relative URLs, let's also remove the old implementation.
As parser now supports context-aware includes, we need to update our unit tests for parser to check that our data-included-from tags are correct. Let's update our unit tests in parser.test.js.
With context-aware includes, all relative URLs should now be with respect to the file that contains the relative URLs, instead of being with respect to the files that are expected to include them. FilterTags needs to be updated so that the reference to Hiding Tags is with respect to its location in userGuide/plugins/.
Our user guide does not mention how users should use relative URL references. Now that parser fully supports relative URL references for images and links, let's update our user guide to document MarkBind's behavior towards relative references. In particular, the intra-site links section has been updated with an important note on how users should specify relative references, while images and pictures section have been updated with a note teaching users that they can now use relative references.
Updated with @Chng-Zhi-Xuan's comments. Thanks :)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 , don't notice any other glaring issues.
• [x] Enhancement to an existing feature
Fixes #822
What is the rationale for this request?
After our parser includes a file, it's context is discarded.
This means that in subsequent passes of parser, we do not know where
the content has been included from, and included content is treated
uniformly as if they were originally part of the file.
This means that content in an included file must be valid wherever
it is included from. For example, resource references need to be
absolute paths, so that they remain valid wherever they are included
from.
This makes it impossible to support relative src references written using Markdown, as markdown code is only parsed after all the includes have been made.
What changes did you make? (Give an overview)
To support context-based references, i.e. the included segments
retain awareness of their original include locations, let's add
a data-included-from meta whenever we include files. To maintain
the existing behaviour and to prevent leaking file structure data,
this meta tag is removed before we finish generating the final
website.
Breaking changes
Previously, some relative URLs are allowed. The reference was always made against files which initiate the include.
Now, any reference is always made against files using the relative URLs.
This should make it more intuitive for authors to reuse content, but may break existing code especially if they are generated using nunjucks/macros.
Provide some example code that this change will affect:
Given this directory structure:
Assume that we have a tutorial file that simply collates a list of content:
And assuming we have the existing content file:
The existing content file is correct because the generated tutorial.html file will have a correct relative reference to index.html, the homepage of the user guide.
However, after this PR, the existing content file is incorrect.
index.html
will refer to an index file within subFolder. All relative references to resources and links are now with respect to the file that writes these references, so in this case, they are made with respect tocontent.md
.content.md should be updated as
Is there anything you'd like reviewers to focus on?
As this PR is significantly breaking and likely to be buggy, please help me test as much as possible and point out any bugs so that I can correct them ASAP.
Sites confirmed working:
[x] Our system test site
[x] CS2103T website
[x] TE3201 website
List of known issues:
All known issues to date are resolved.
Progress:
[x] Finish testing against all existing websites and ensure that there are no bugs
[x] Update documentation to reflect change against relative URL references
[x] Determine reason behind unwrapping div bug. Update: bug is due to difference between span and div used for inline and non-inline includes. Bug squashed.
[x] Determine why tests aren't correct - and whether to update tests or to find bug. Update: bug squashed.
Testing instructions:
Please check out this PR and build it against existing, known good sites and verify that the sites are working as expected.