Comments (5)
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.
from org_to_anki.
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 org_to_anki
to automatically encode HTML special characters?
from org_to_anki.
I've made a simple (maybe dirty) hack to get around this by modifying the _formatFile
function located at src/org_to_anki/org_parser/parseData.py
:
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.
from org_to_anki.
It turns out my previous answer created another problem. Now, the code blocks with <
/ >
are escaped into <
/ >
, respectively.
So, I've reverted the change made and added the following to src/org_to_anki/AnkiClasses/AnkiQuestionFactory.py
:
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 DeckBuilderUtils
or somewhere else.
from org_to_anki.
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
line = escape(line)
looks like the right idea. There should be some way of encoding it so that it get correctly escaped.
I will mark this as a bug and try get a fix done this week
from org_to_anki.
Related Issues (20)
- does not support Arabic HOT 5
- Support sync of text files to Anki deck - edits / deletions / new cards HOT 3
- What is the second script? HOT 2
- Auto cloze from a wordlist.txt HOT 3
- How to add an image to Extra field of Cloze? HOT 7
- Support image inline for Emacs
- Support for .pdf not available as answer, rather than only .png (image) HOT 1
- Support for .html not available as answer, rather than only .png HOT 6
- Non-Technical Help Request HOT 10
- Remove usage references to Word in the readme HOT 1
- Investigate issues that causes missing html in bs4 4.9.1
- Lists to Anki issue HOT 3
- long lines in the top level of bullets are truncated before they appear on "Front" in Anki HOT 6
- The error was 'list' object has no attribute 'contents' HOT 2
- The error was “list” object has no attribute “contents”
- The error was Line incorrectly processed..
- utf-8' codec can't decode byte 0xca in position 2265: invalid continuation byte
- false-positive alert in the report to the CLI for .org with UUID
- feature suggest, extending org-based Anki import of code snippets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from org_to_anki.