Archived
1
0
This repository has been archived on 2023-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
luminotes/view/Html_file.py
Dan Helfman 2c20d60f9e * Rewrote all wiki note links to be of the form: /notebooks/notebookid?note_id=noteid
* Refactored some of validator decorator to use clearer variable names internally.
 * Validator decorator now supports treating arguments with default values as optional.
 * controller.Notebooks.default() takes an optional note_id argument.
 * controller.Notebooks.contents() takes an optional note_id argument.
 * Wiki.js now makes use of these new controller APIs.
 * Editor.js now takes a notebook_id argument to its constructor so it can properly make links.
2007-07-28 04:22:44 +00:00

41 lines
1.3 KiB
Python

import re
import cherrypy
from Tags import Html, Head, Title, Style, Meta, Body, H1, Div, Span, Hr, A
class Html_file( Html ):
NOTE_LINK_PATTERN = re.compile( u'<a\s+href="\/notebooks\/[a-z0-9]*\?note_id=([a-z0-9]*)"\s*>', re.IGNORECASE )
def __init__( self, notebook_name, notes ):
relinked_notes = {} # map from note id to relinked note contents
# relink all note links so they point to named anchors within the page
for note in notes:
contents = self.NOTE_LINK_PATTERN.sub( r'<a href="#note_\1">', note.contents )
relinked_notes[ note.object_id ] = contents
cherrypy.response.headerMap[ u"Content-Disposition" ] = u"attachment; filename=wiki.html"
Html.__init__(
self,
Head(
Style( file( u"static/css/download.css" ).read(), type = u"text/css" ),
Meta( content = u"text/html; charset=UTF-8", http_equiv = u"content-type" ),
Title( notebook_name ),
),
Body(
Div(
H1( notebook_name ),
[ Span(
A( name = u"note_%s" % note.object_id ),
Div(
relinked_notes[ note.object_id ],
class_ = u"note_frame",
),
) for note in notes ],
id = u"center_area",
),
),
A( "Luminotes", href = "http://luminotes.com/" ),
)