Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
reMarkAble/remarkable/section.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
101 lines (76 sloc)
2.76 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
reMarkable: Convert markdown to docs using Templates | |
Copyright (C) 2020 Dan Goldsmith (djgoldsmith@googlemail.com) | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <https://www.gnu.org/licenses/>. | |
""" | |
import remarkable.renderer as renderer | |
class Section(): | |
"""Class for Sections | |
At the moment a placeholder for sections. Lets me parse and work | |
out all the meta data | |
""" | |
def __init__(self, text, marks=None, maxMarks=None, header=None): | |
self.text = text | |
self.marks = marks | |
self.maxMarks = maxMarks | |
self.header = header | |
def updateMarks(self, marks, maxMarks=None): | |
""" | |
Update the marks awarded for a section | |
WARNING: You will need to cast the marks. | |
""" | |
self.marks = marks | |
self.maxMarks = maxMarks | |
def asStr(self): | |
""" | |
Render the text as a string | |
Here we will strip out the first and last items if they are | |
empty. This is a side affect of the parsing process | |
""" | |
temp = self.text | |
if temp[0] == "": | |
temp = temp[1:] | |
if temp[-1] == "": | |
temp = temp[:-1] | |
return "\n".join(temp) | |
def markdown(self): | |
""" | |
Render the text as from markdown | |
TODO: Consider this as it may be more applicable to do it in | |
the rendrer | |
""" | |
inText = "\n".join(self.text) | |
html = renderer.markdowner.convert(inText) | |
return html | |
def __str__(self): | |
"""String representation. | |
Renders the text as Markdown, and returns it. Makes templates | |
much cleaner as we don't need to call the markdown() | |
explicitly | |
""" | |
return self.markdown() | |
def getMarks(self): | |
""" | |
Render the marks | |
Either show the awarded marks, | |
or the Awarded Marks as part of a total | |
<Awarded> | |
<Awarded> / <Max> | |
return: String representing our marks (or False if no marks) | |
""" | |
if self.marks: | |
if self.maxMarks: | |
return "{0} / {1}".format(self.marks, self.maxMarks) | |
else: | |
return "{0}".format(self.marks) | |
else: | |
return None |