-
Notifications
You must be signed in to change notification settings - Fork 132
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
Convert relative src references to absolute paths #677
Conversation
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.
I found an edge case you didn't cover. If you put a <pic>
component within <panel>
it will not change the src
.
In index.md |
In images/subsite.md |
---|---|
<include src="images/subsite.md"></include> |
<panel header="### test-pic"> <pic src="om.jpg" alt="om-pokemon"></pic> </panel> |
EDIT:
Checked out PR 667
instead of PR 677
for testing.
Tested on PR 677
and the above example works.
Checkout wrong branch for testing
How's this going? |
I've been working on SE-EDU over the past couple of weeks, so I haven't done much here. The old syntax will continue to work as this will only change relative URLs, and yes, thanks for the reminder. Will update the docs too. |
4ff88ea
to
d6c0d87
Compare
Just pushed an update to this PR. Also works for URIs involving variables: {{baseUrl}}/path/to/file. However, this assumes that a path starting with {{ means an absolute path. I'm not sure if this is a good idea. I have updated the PR issue with some things I need help with, from reviewers. |
@Chng-Zhi-Xuan something's broken right now, please don't review it yet! :) |
I've updated the code and added unit tests.
Ready for review @Chng-Zhi-Xuan |
Edit: I just noticed this. I'll fix the docs up. |
Perhaps also remove all unnecessary |
baee282
to
8c36434
Compare
Okay :)) |
f40ea57
to
7e64521
Compare
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 message: For "Convert dynamic src references to absolute paths"
Currently, dynamic resource references in src attributes for pic/img tags,
as well as href attribute for a tags are broken during reuse.
-
The "Currently" wording is redundant; we automatically assume that the starting paragraph is talking about the current situation before this commit happens.
-
It is insufficient to say that it is broken. The "why is it broken?" needs to be stated as well (the fact about outer documents when including inner documents, they do not care that paths used by the inner documents are with respect to the inner document, and NOT to the outer documents, hence the outer document needs to resolve the path rather than blindly including it).
-
as well as href attribute for a tags
: As first I thought it was a typo, I think you meant anchor & link tags right? Since 'a' is such a short name, you should spell it out to "anchor" to avoid potential confusion.
Hence, let's convert all dynamic resource references to static references,
so that it will work consistently across all sites and sub-sites.
This is not just a problem with sub-sites actually, but it also affects any files residing inside an inner folder (Btw, just to clarify in case you misunderstood the term, sub-sites are folders with their own site.json
, not all folders inside an existing website is considered a sub-site).
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 message: Documentation: Remove unnecessary {{baseUrl}}
Not wrapped at 72 characters. :P
Also commit message should specify why baseUrl was used in the first place. The documentation used baseUrl because:
- Relative path was not supported.
- If baseUrl is not empty, not all URLs are resolved correctly by MarkBind.
These features are now available, so we remove baseUrl in this commit to make it easier to maintain the documentation.
You can also mention about not altering the .mbdf with the reason you stated in the first post.
@sijie123 need you to resolve conflict for this PR; all PRs were affected by the recent master branch rebase. |
Done. Thanks for the heads-up! |
Updated original post to include "fixes #661". |
When including files from a sub-site or a sub-folder within the same site, Markbind only automatically resolves src references for the include and panel tags. This means that references to any other resources (such as anchor#href, img#src and pic#src) do not get resolved and converted. When these markdown files containing relative resource references are included by another file in a different directory, the links remain unchanged. From the perspective of the outer document, the references become broken and files become not found. To resolve this problem, let's convert all relative resource references to absolute ones. This allows the references to work consistently across all instances of reuse. This conversion process adds on to the existing preprocess step and is similar to how we currently resolve src references in include and panel tags.
The documentation uses {{baseUrl}} to create absolute references to many resources, including CSS files, links and images. This was necessary because we did not have features to support dynamic resource references. To ensure that our sites render consistently regardless of the page that the user is in, we manually referenced each resource with respect to an absolute {{baseUrl}}. This is no longer necessary, as we can now support relative paths. As Markbind can now automatically convert relative resource references to absolute ones, we can remove {{baseUrl}} to make it easier to maintain the documentation in the future. In this commit, all unnecessary references to {{baseUrl}} have been removed, except for mbdf files within userGuide/syntax and userGuide/plugins. These files are meant as the central reference within the user guide, and removing {{baseUrl}} from these files might make it confusing to maintain or add new documentation in the future.
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 again, didn't notice any critical issues.
@sijie123 this doesn't seem to work when the file containing the relative link is included somewhere else. Is it supposed to? |
In fact, it seems to work for |
If I understand your question correctly, are you trying to include files across different sites? (ie site_one trying to include site_two/file.md, where site_two is not a sub-site or sub-folder of site-one)
This however, seems to be an issue. I implemented the code with the assumption that markdown code will first be converted to html before we do any parsing. It seems that this is not the case? (@yamgent / @Xenonym: do you guys know how our parser layers work?) |
It's within the same site, not even a subsite, but the problem is limited to only the |
Lines 776 to 796 in 40f3e7a
I completely forgotten about the markdown syntax equivalents, we are doing the relative src referencing in the wrong pass. |
😱 I think I'll have to discuss this issue with you on Thursday... |
Yes looks like we will have to introduce an additional Then again, if a developer fears adding a new layer, that is a sign that that part of the code is too intertwined, and needs to be refactored into more logical units. 😛 |
For future reference, the follow-up issue is resolved by #826. |
What is the purpose of this pull request? (put "X" next to an item, remove the rest)
• [x] Documentation update
• [ ] Bug fix
• [ ] New feature
• [x] Enhancement to an existing feature
• [ ] Other, please explain:
Fixes #598
Fixes #661
What is the rationale for this request?
Currently, authors can use dynamic references in include tags.
However, if authors use dynamic resource references in src tags for pic/img etc, these references may cause broken links when re-used. This request converts all dynamic resource references to static references, so it will work consistently across all sites and sub-sites. At the same time, this request should be backward compatible, so that authors using older workarounds should expect their site to continue working.
What changes did you make? (Give an overview)
During the preprocess stage, in addition to preprocessing includes, also preprocess media resources (e.g. pic) to convert all dynamic references to static ones with respect to the root path (where site.json is located)
Additionally, removed unnecessary use of {{baseUrl}} from the user guide, changing all such links to static references. However, I did not touch mbdf files within
userGuide/syntax
anduserGuide/plugins
, as relative references might make it confusing to write these files in the future.Provide some example code that this change will affect:
Refer to #598
Folder structure:
index.md
subsite.md
New syntax changes
Authors can now also use relative src references in
img
,pic
tags, as well as relative href attributes ina
andlink
tags.To use
{{variables}}
are treated as absolute paths, and will not be modified.Breaking changes
There should be no breaking changes. I tested against the old unit tests (I didn't modify anything) and code is passing. I have also added unit tests to ensure that future changes will retain this behaviour.
My PR might break existing documents if authors used incorrect URI statements like
/{{baseUrl}}/path/to/file
. Notice that this string, in the original version, essentially resolves to//rootFolder/path/to/file
with 2 forward slashes. While previous versions might be lenient, my conversion requires stricter syntax and might result in broken links.Is there anything you'd like reviewers to focus on?
Are there scenarios where this change would cause something to break? I've tested on unit tests and CS2103-website.
Testing instructions:
Replicate the folder structure as above. Be sure to include dynamic references to media resources. Run markbind serve, then view the generated webpage.