Development

Configuration

geekbook - config file

Geekbookapp

Page

Page - one note is a page.

class engine.page.Page(fn)[source]

Page class

Attributes:

fn - filename of the note, with .md md - md content of the note html - html content of the note
compile()[source]

Preprocess, compile, postprocess.

get_html()[source]

Compile md to get html

is_changed()[source]

Check if the file on disc is different than md.

Make PATH_TO_ORIG if it does not exists.

Return:
boolean
post_process()[source]

Do postprocessing

pre_process()[source]

Do preprocessing.

E.g.:

self.md = get_image_path(self.md) 
save()[source]

Save html file to the drive

Make Index

geekbook - make index

Get the list of md with sys.stdint.read() and generate html index.html. The top of the html file is defined here, see the html variable. The second part is generated in the loop, per md make a link in the index.html.

Make Table of Contents

geekbook - table of content

Get markdown output and make a table of content!

h1 How my lifebook should look? id_of_div How-my-lifebook-should-look?

changelog:

2012
  • 0831 fix of the previous point
  • 0829 make h1 clickable
engine.make_tableofcontent.tag_heading(heading)[source]

Find all tags in a heading and replace it with “my” tags

Get: - heading

Return: - heading with “my” tags

Preprocessing

This is a set of functions that work on Markdown file, before compiling them to html.

Go to page.py (Page) pre_process to add a new function from here.

engine.preprocessing.change_todo_square_chainbox_or_icon(text, verbose=False)[source]

Set of rules to replace [i] etc with <img … > [ OK ]

engine.preprocessing.get_abstract(text)[source]

Collect all lines starting with ``! `` and insert it as in abstract in a place tagged as [abstract].

Now you can use ** to bold some text. You can use to introduce a break (</br>).

engine.preprocessing.get_image_path(text)[source]

Get image path for text. See get_image_path_in_line (to get links per line) to learn more.

engine.preprocessing.get_image_path_in_line(l)[source]

Update: work also with more than one link per line and with tables. Update (2): you can also define width and height of your images.

Only width, e.g.:

![](imgs/Screen_Shot_2017-02-12_at_1.17.04_AM.png =500x)

only height:

![](imgs/Screen_Shot_2017-02-12_at_1.17.04_AM.png =x400)

and both:

![](imgs/Screen_Shot_2017-02-12_at_1.17.04_AM.png =400x400)

You can use internal variable log to switch on and off logging.

engine.preprocessing.include_md_files(md)[source]

Whenever you see /<file.md> include content of this file in here.

Args:

md (str): context of a md file

Returns:

str: new md (nmd)
engine.preprocessing.right_MD_from_webservices(text)[source]

Just paste the url generated by Dropbox to convert it in a markdown img

Postprocessing

This is a set of functions that work on HTML file, after compiling them based on Markdown.

engine.postprocessing.add_head(text)[source]

Add head html from template

engine.postprocessing.add_title(text, title)[source]

title is self.md, remove .md

engine.postprocessing.change_data_tag_into_actual_data(mdfn, text)[source]

change [date] into actual date

engine.postprocessing.change_html_tags_bootstrap(text)[source]

searches for html tags and adds the proper bootstrap class

engine.postprocessing.change_todo_square_chainbox_or_icon(text, verbose=False)[source]

Set of rules to replace [i] etc with <img … > [ OK ]

engine.postprocessing.get_captions(text)[source]

Replace in text @todo, @inprogress and @done with <span class=”label label-danger”>@todo</span> and so on.

engine.postprocessing.get_todo(text)[source]

Replace in text @todo, @inprogress and @done with <span class=”label label-danger”>@todo</span> and so on.

engine.postprocessing.personal_tags_to_html(text)[source]

insert here your personal tags!

engine.postprocessing.use_icons(text)[source]

https://www.w3schools.com/bootstrap/bootstrap_badges_labels.asp

Plugins

Insert Image

engine.plugins.insert_image.insert_image(d='/home/magnus/Desktop/{*png, *jpg, *jpeg}', td='/home/magnus/Dropbox/geekbook/notes/imgs/', IMG_PREFIX='imgs/')[source]

Check the latest file in d-rectory and copy it to t-arget d-rectory

engine.plugins.insert_image.insert_image_in_md(text, sd, td, IMG_PREFIX, verbose=False)[source]

Go over each line and check if there is ii. If yes, then run insert_image function.

Args:
text (str): The path of the file to wrap d (str): source directory td (str): target directory IMG_PREFIX
Returns:
Text

Flask-based actions

Run the server:

[mm] geekbook git:(master) ✗ python engine/webserverflask.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

and open in your browser http://127.0.0.1:5000/edit/test.md (you can add this to your notes <a href="http://127.0.0.1:5000/edit/test.md">edit</a>.

To add new function, build on this simple example:

@app.route('/edit/<note_title>')
def edit(note_title):
        """Open a note with your edit"""
        os.system('open ../notes/' + note_title)
        return 'edit note: %s' % note_title

Webserver

# get ip of visitors https://stackoverflow.com/questions/3759981/get-ip-address-of-visitors

engine.webserverflask.edit(note_title)[source]

Open a note with your edit

engine.webserverflask.edit_header(note_title, note_header)[source]

edit_header::cmd: cd /Users/magnus/Dropbox/geekbook/notes/ && /usr/bin/grep -n ‘# h1 Heading’ test.md edit_header::out: 11:# h1 Heading

Old: grep

grep -n ‘May #2’ *.md lifebook.md:7:# May # Open a note with your edit

http://stackoverflow.com/questions/3139970/open-a-file-at-line-with-filenameline-syntax

..warning: if two headers found there will be a problem ;-)

engine.webserverflask.view(note_title)[source]

Open a note with your edit

DataTables

Html code to be inserted dataTables [1] for index can be found in engine/make_index.py.

[1] https://datatables.net/