-
Notifications
You must be signed in to change notification settings - Fork 408
Description
⚠️ This issue respects the following points: ⚠️
- This is a bug. Not a question or feature request.
- The topic is not already reported at Issues. (I've searched it).
- Markor is up to date. See Releases for the latest version. Updates are available from F-Droid and GitHub.
- The bug is still present in the latest development version (git master). (Please download and try the test version of Markor, named Marder. Don't worry; Markor and Marder appear as completely separate applications. You can install both side-by-side, and Markor settings are not touched. In case the issue is resolved there, you don't need to create a bug report. The change will be part of the next Markor update.)
Description
I was debugging my own injected script not working anymore. I found what I believe is a bug that will break all injected scripts that use onPageLoaded() to execute their code.
Here is a snippet of the generated html file which has the first script block being my injection through the app settings, the rest is generated by the app itself.
<script type="text/javascript">
function onPageLoaded(){
document.querySelectorAll("p").forEach(el => el.setAttribute("style","color:red"));
}
</script><script> function onPageLoaded_markor_private() {
wrapCodeBlockWords();
onPageLoaded(); }
</script></head>
<body class='format-markdown fileext-md' onload='onPageLoaded_markor_private();'>
The problem is that there is no function definition for wrapCodeBlockWords anywhere in the file, so this appears to break execution resulting in onPageLoaded never being called.
By injecting my own definition for wrapCodeBlockWords i can fix the execution cycle and ensure that onPageLoaded is called. see steps to reproduce
Steps to reproduce
- insert a simple js snippet that should run in settings -> view mode -> inject head ie:
<script type="text/javascript">
function onPageLoaded(){
document.querySelectorAll("p").forEach(el => el.setAttribute("style","color:red"));
}
</script>
- create a new empty .md file
- edit the file and insert some text to generate at least one
<p>
tag in the view mode. - view the .md file in Markor/Marder
- note that the injected snippet does not execute. no red text.
- Edit the above injected snippet to the following:
<script type="text/javascript">
function onPageLoaded(){
document.querySelectorAll("p").forEach(el => el.setAttribute("style","color:red"));
}
function wrapCodeBlockWords(){}
</script>
- view the .md file again in Markor/Marder
- the injected snippet should execute
note:
I included the hack/workaround that fixes the execution above as I wanted to be sure that resolving the undefined reference would fix the issue purely inside the app.
In order to find it in the first place I used the share as html to export what I assume is the same html file being viewed in the app.
However I cannot guarantee that the view mode is rendering the same exported html, or that the export process is adding or removing anything.
But this method of exporting could also be used to investigate the issue.
Information
Android version: 14
Device: samsung galaxy a15 5g
Markor App Version: 2.12.4
Marder App Version: 2.12.5-2245
Source
F-Droid
Format / File type
Not specific
Additional info / Log
I did a quick check on other file types that can be created within the app:
1. create an empty file of X type in app
2. share as html
3. inspect html output for undefined reference to wrapCodeBlockWords
Affected:
Markdown
wikitext/zim
CSV
Unaffected:
plain
todo
asciidoc
orgmode