Skip to content
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

Print branch #48

Closed
MareoRaft opened this issue Jul 25, 2017 · 12 comments
Closed

Print branch #48

MareoRaft opened this issue Jul 25, 2017 · 12 comments

Comments

@MareoRaft
Copy link
Owner

MareoRaft commented Jul 25, 2017

Print

This branch which I haven't even started yet allows a user to print a node or nodes or a curriculum. The idea is simple. Browsers are already capable of printing what you see on an HTML page very effectively. Therefore, an easy and straightforward solution is to produce a basic HTML page from a node (or nodes, or curriculum) that is almost the same as we already have, but with a few things simplified.

Instead of using blinds, we can simply have headers/subheaders using <h2>. There is no need for node-template icons such as "learn" and "edit" and "save". Other than that, everything is pretty much identical to what we already have, including the running of mathjax to get pretty math.

The HTML that we produce (after a user clicks "printable page") is opened in a separate page, just like I did in Andrew's groceries repository.

@MareoRaft
Copy link
Owner Author

MareoRaft commented Jul 28, 2017

This is now working AFAIK. A little cleanup, then merge with master. Merged.

@MareoRaft
Copy link
Owner Author

MareoRaft commented Jul 28, 2017

I FORGOT. We still need to

  1. run MARKED on the server-side in order for this to be completely finished.
  2. say "thm" or "defn", etc instead of "description" for the description attribute.

@MareoRaft MareoRaft reopened this Jul 28, 2017
@MareoRaft
Copy link
Owner Author

  1. finished. Still need 1.

@MareoRaft
Copy link
Owner Author

Let's also add

  1. the number, but smaller font (use span and CSS) immediately below the title(name).

MareoRaft added a commit that referenced this issue Jul 30, 2017
…description attribute. feature to the printable_html feature (issue #48)
@MareoRaft
Copy link
Owner Author

  1. finished. Still need 1.

@MareoRaft
Copy link
Owner Author

MareoRaft commented Aug 5, 2017

We shall now run ./Markdown.pl (in server/lib) on an input

https://github.com/JanSchulz/knitpy

i'm so lost. I was just trying to use Markdown.pl directly, but tempfile module is misbehaving. the Markdown reads the file, it reads it as blank :( Opened a SO question about it:

https://stackoverflow.com/questions/45517816/python-write-to-temp-file-and-read-from-command-line

@MareoRaft
Copy link
Owner Author

This markdown to html thingy is apparently more widely used, and I should now try it out: https://github.com/trentm/python-markdown2

@MareoRaft
Copy link
Owner Author

It seems to be the same behavior as the JS marked library, so let's move forward with it! Now remember that we customized markdown, so I have forked the library and I must make the following customizations:

  1. SINGLE underscores do NOTHING instead of ITALICS.
  2. DOUBLE underscores do UNDERLINING instead of BOLD

This probably needs to be done in python-markdown2/lib/markdown2.py at def _do_italics_and_bold(self, text).

MareoRaft added a commit that referenced this issue Aug 6, 2017
@MareoRaft
Copy link
Owner Author

MareoRaft commented Aug 6, 2017

This is WORKING. 4 and 5 resolved. But markdown2 has this one side effect where displaystyle math delimited by

\[ and \]

no longer gets processed by mathjax. Somehow, markdown causes the \[, for example, to be relaced by [ in the ultimate HTML.

I started a GitHub issue for this: trentm/python-markdown2#266

@MareoRaft
Copy link
Owner Author

Just for kicks, I was able to get the original Markdown.pl to work. It turns out to have the same behavior as marked2. So this weird behavior above is actually standard. It must actually be marked (in JS) that behaves differently than the "standard". Anyway, the marked behavior is what we want... :(

@MareoRaft
Copy link
Owner Author

If I want to change the behavior of marked2 manually, I think the relevant code is

# Table of hash values for escaped characters:
g_escape_table = dict([(ch, _hash_text(ch))
    for ch in '\\`*_{}[]()>#+-.!'])

and

def _encode_backslash_escapes(self, text):
    for ch, escape in list(self._escape_table.items()):
        text = text.replace("\\"+ch, escape)
    return text

MareoRaft added a commit that referenced this issue Aug 7, 2017
…nd probably faster, and behaves exactly like Markdown.pl. This concludes issue #48
@MareoRaft
Copy link
Owner Author

Okay so I just replaced \[ and \] with an escape sequence before running markdown, and then changed it back after markdown. Hope there are no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant