-
Notifications
You must be signed in to change notification settings - Fork 10
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
HTML elements not rendered correctly in question statements #80
Comments
I've found standard library function that does exactly that: from html import escape
escape("<li>") Output: '<li>' I think it only works on certain versions of Python though, but I'm not completely sure. If you want more information, check out this StackOverflow question from which I found the answer. Could this be included into |
I've made a simple (maybe dirty) hack to get around this by modifying the def _formatFile(filePath):# (filePath: str):
from html import escape
with open(filePath, mode="r", encoding="utf-8") as file:
data = file.read().split('\n')
# escape HTML special chars
data = [escape(line) for line in data]
return data Now it works like a charm. Let me know if you want me to create a PR or something to include this feature/fix. I haven't written tests or documentation though. It's just a little hack to get me going. |
It turns out my previous answer created another problem. Now, the code blocks with So, I've reverted the change made and added the following to class AnkiQuestionFactory:
...
def buildQuestion(self):
from html import escape
...
for line in self.currentQuestions:
line = self.utils.removeAsterisk(line)
line = self.utils.formatLine(line)
+ # Escape HTML special characters
+ line = escape(line)
line = self.utils.parseAnswerLine(line, self.filePath, newQuestion)
newQuestion.addQuestion(line)
... Now it does what I want. I haven't followed much the conventions used for the project because I just wanted to get this to work. Maybe it would be better to move the changes into the |
Sorry for the delay in getting back to you! busy weekend. I will have a look over it it the next few days I would like to be able to support such functionality. I think your last comment for I will mark this as a bug and try get a fix done this week |
Ok, thanks! By the way, I've found another related issue. Even with this fix, if you write HTML characters in answer statements they don't get encoded correctly and end up breaking the lines. Example file: * Question <li>
** Answer <li> Output (in Anki): Question <li>
- Answer
- Note: the answer line breaks into two. I think if you were to escape all text (questions and answers), except for code blocks (which already escape these characters) it would work. I don't know exactly what exactly has to be done. I'll try to look into it if I have time this week. |
Please follow the template below to report your issue.
Please include the following information:
Any general information
Hi there! I want to be able to write the following question:
* How do you generate <li> elements with pug
But when I run
org_to_anki
the tags ("<", ">") dissappear and the line breaks into multiple lines, like so:If instead I use
<
and>
in the question statement it works fine. But the character sequences are fairly tedious to write. Is there any way around this?I've also tried using accents (`) to escape the characters but it gives me the following:
Raw text of the file you tried to upload
* How do you generate <li> elements with pug
Error report from the popup
There's no error report from Anki.
What is your operating system
Ubuntu 16.04.
What was the original file type
Text file.
The text was updated successfully, but these errors were encountered: