Package: hackernote
HackernoteReference library to parse and render hackernotesThis project is part of thePyrustic Open Ecosystem.Installation.Latest.DocumentationTable of contentsOverviewFile extensionExampleAPIRelationship with INI file and TOMLRelated projectInstallationOverviewHackernoteis a Python package which is the reference library to parse and renderhackernotes.Hackernoteis a file format for thehackernotes. Ahackernoteis a text withsections. Each section has atitleand abody. The title of a section is written on a separate line between twosquare brackets. A text produced by a hacker without a section title is still ahackernotesince thenull titleexists.Ahackernoteis so easy to parse that I dropped the first regex-based iteration.Fun fact:The codebase documentation forPyrusticprojects is generated with a tool that parsesdocstringsexpressly written in thehackernoteformat.File extensionYou can proudly add the.hknfile extension to yourhackernotes.ExampleHere is the contents of a fictitiousexample.hknfile:This section has a 'null title' since the title is missing.

[section_1]
A title is a string surrounded with square brackets.
Do not put spaces in the title.

[todo-list]
item_1: 1
item_2: 2
# The library offers the 'get_key_value' function to split 
# a line into key-value parts.
# Am I writting comments ?
# If you think that this is a comment... so ok, this is a comment...
...
Hey, stop thinking about TOML or INI file, only two things matter here:
- a section title
- a section body

[section_1]
No exception will be raised. This is not a duplicate section.
This is simply a continuation of [section_1] (yes I can write it here !)

[]
This is the second time you've come across an empty title section in this hackernote.

[empty-body-section]APIThree functions are exposed by theHackernotelibrary:parse:This function takes as input a filename or a string and returns thehackernote structure. The hackernote structure is a dictionary. A key is a section title and the value is a list of strings that make up the body of the section. Each string represents a line. The order of the keys is the same as in the original hackernote.render:This function takes as input ahackernote structureand optionally a destination filename. The hackernote structure is then rendered, i.e. a text is output (optionally saved to a file).get_key_value:This function takes a string as input and then divides it into key and value parts. You can set the separator character. By default, the separator is:.importhackernote# parse the content of the source fileSOURCE="/path/to/note.hkn"structure=hackernote.parse(SOURCE,compact=True)# iterate over the hackernote structurefortitle,bodyinstructure.items():print("Section title:{}".format(title))print("Body: ")# body is a list of strings (lines)str_body="\n".join(body)print(str_body)print()# convert the structure into a compact plain text,# then save the result in the destination fileDESTINATION="/path/to/compact_note.hkn"text=hackernote.render(structure,destination=DESTINATION)# print the compact version of the content of the source file,print(text)Relationship with INI file and TOMLExcerpt from the Wikipedia page of theINI file:The primary mechanism of software configuration in Windows was originally a text file format that comprised text lines with one key–value pair per line, organized into sections. This format was used for operating system components, such as device drivers, fonts, startup launchers. INI files were also generally used by applications to store individual settings.Excerpt from the Wikipedia page ofTOML:TOML's syntax primarily consists of key = "value" pairs, [section names], and # comments. TOML's syntax somewhat resembles that of .INI files, but it includes a formal specification, whereas the INI file format suffers from many competing variants.Its specification includes a list of supported data types: String, Integer, Float, Boolean, Datetime, Array, and Table.Hackernoteshares with theINI fileandTOMLthe square brackets and the concept ofsection.And that's all.Also,Hackernoteis topic agnostic. You can use it to saveHacker Newslinks, use it to save code snippets, or use it as a configuration file (like I did withBackstage). You can even decide to use it as a docstring format (modules documentationare generated from these docstrings). Only you can decide what a comment is, what should be considered key-value, what should be treated as float, boolean, text, etc.Hackernotesolvesthis(TOML) andthis(INI file) out of the box !Related projectBackstageis alanguage-agnosticcommand-line tool that allows the developer to define, coordinate and use the various resources at his disposal to create and manage a software project.Backstagemakes extensive use ofHackernote.DiscoverBackstage!InstallationHackernoteiscross platformand versions under1.0.0will be consideredBetaat best. It is built onUbuntuwithPython 3.8and should work onPython 3.5ornewer.For the first time$pipinstallhackernoteUpgrade$pipinstallhackernote--upgrade--upgrade-strategyeagerBack to top