lmd

package
v0.0.0-...-12747d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssembleParametersIntoJSON

func AssembleParametersIntoJSON(contents string, parameters map[string]string) string

HandleParameterAssemblyJSON performs roughly the same parsing function as the HandleParamaterAssembly function.

The major difference is that once the four maps are established by the search functions then each of the keys and values in these maps are copied back into the parameters map.

Finally the reassembled parameters map is marshaled into a JSON string that is returned to the calling function.

func GetTheParameters

func GetTheParameters(contentsFile string) string

GetTheParameters is a wrapper function which enables a system to determine what the parameters of a given template file are. It will first look at the file to determine if there is front matter which can be parsed. If there is front matter that will be sent to a function which essentially just marshals the json into a string that is returned to any calling function.

If there is no front matter within the template function, the AssembleParametersIntoJSON function will be called. This function is analogous to the HandleParameterAssembly function which will write to YAML front matter, except that the AseembleParametersIntoJSON function will marshall the parameters into a JSON string that will be returned to the calling function.

func HandleMixins

func HandleMixins(contents string, parameters map[string]string) (string, map[string]string)

HandleMixins is the primary handling function for the mixin and optional clause parsing exercise which is a subset of the overall parse job.

The first thing which the function will do is to extract the parameters which we know are applicable to the structured_headers portion of the overall parse job rather than the mixins portion of the overall parse job. These parameters are parked into a new map during the remainder of the mixin operation.

After the parameters we do not want to handle have been parked, the function then runs through the optional clauses parse adding those optional clauses which have been turned on, and taking out of the final document those optional clauses which have been turned off.

When the optional clauses have finalized, then the function runs through the simple text mixins and replaces all of the keys established in the text of the template with the values established in the parameters.

Finally a simple cleanup function is called to compress extraneous white space and then the function returns the parsed and corrected contents along with the parked parameters which are relevant to the structured_headers phase of the overall parse.

func HandleParameterAssembly

func HandleParameterAssembly(contents string, parameters map[string]string) string

HandleParameterAssembly is the primary parsing function which is used by the cli assemble method and any libraries seek to build YAML front matter for a template file.

The function accepts a string of content and a map of parameters.

First the function will establish four maps, one each for the mixins, the optional clauses, the headers, and they style parameters. Then the function will run through searching functions to handle the assembly of each of these four major elements.

If any parameters have been sent to the function via the paramaters map, the values in each of the parameters field will be maintained. If the keys in the parameters map do not exist, but the appropriate mixin, optional clause, or header exists in the text of the template, then the appropriate key will be added to the appropriate map.

Lastly the function will call a function that will reassemble the file by running through each of the maps and building the front matter. The reassembled contents are returned to the calling function.

func HandleTheHeaders

func HandleTheHeaders(contents string, headers map[string]*Header) string

HandleTheHeaders is the primary parser function for parsing a block of structured headers.

The function begins by calling the findTheBlock function with the full contents of the file. This function returns a boolean which tells the HandleTheHeaders function whether there is a block to parse or not. If there is no block, this function simply returns the full contents to the calling function. If there is a block, this is parsed into the pre_block, block, and post_block variables by the findTheBlock function.

The block is then passed to the splitTheBlock function which breaks the block into its pieces as delimited by whether there is a structured_header at the beginning of the line or not. two slices are returned by the splitTheBlock function. The first is the blockBase slice which includes only the headers used in the block. This slice is used by the tree parsing to determine whether the parser is going up or down the tree or staying at the current location. The second slice is the blockAsSlice which contains the full contents of the block broken into pieces according to whether there is a structured header or not. This slice is what is used by the parser to fill out the contents.

Once these slices are established, they are passed to the runTheHeaders function along with the headers map. This function has the primary parsing functionality. It iterates and the headers as determined by the trees established within the template file. This function returns a string which is the new block reassembled with the structured headers emplaced.

Finally, the contents are reassembled by adding the pre_block variable to the block and post_block variables which is a long string that is returned to the calling function.

func LegalToMarkdown

func LegalToMarkdown(contentsFile string, parametersFile string, outputFile string)

LegalToMarkdown is the primary function which controls parsing a template document into a markdown result when the parsing library is called from the command line. Two strings which are filenames should be passed to the function. The parameters string may be an empty string. The function first parses and reads the command sent from the command line, and then reads the template file. After this, the function pulls into the template file any partials which have been included into the template with the `@include {{PARTIAL}}` flag within the text of the primary template file that has been called.

Then the function reads the paramaters from a parameters file, the template file, or both. In the case where the parameters are contained in both a parameters file and in the template file, the parameters in the template file are considered as defaults which are overridden by parameters passed to the function via the paramaters file.

Finally once the function has prepared the `contents` and `parameters` from the various passed files and built a cohesive set of `contents` and `parameters`.

These are passed to the primary entrance function to the parsing process. The contents of the file which needs to be parsed, and the parameters which should control the parsing and transformation of the lmd file to a rendered document are lexed and ready for the parser to run through the sequence of mixins, optional clauses, and structured headers.

The parser will first call the primary mixins function, then will call the primary optional clauses function, and finally it will call the primary structured headers function.

Once the parser has completed its work, it will return to the LegalToMarkdown function the final contents so that that function may call the appropriate writer for outputting the parsed document back to the user.

func MakeYAMLFrontMatter

func MakeYAMLFrontMatter(contentsFile string, parametersFile string, outputFile string)

MakeYAMLFrontMatter is a convenience function which will parse the contents of a template to formulate the YAML Front Matter.

func MarkdownToPDF

func MarkdownToPDF(contentsFile string, parametersFile string, outputFile string)

MarkdownToPDF renders an input template file to pdf using a webservice hosted on https://lmdpdfgen.herokuapp.com/

It runs through the normal parsing system but instead of sending to the standard writer it sends the result of the parsing job to the WriteToPdf function which will send the result of the parse job to the web service and write the result to the output file location.

func RawMarkdownToPDF

func RawMarkdownToPDF(rawContents string, rawParameters string) string

RawMarkdownToPDF is a function which does not work with written or written_to files instead of dealing with files to be read, the function simply parses strings which are passed to it programmatically. Otherwise the function logic mirrors MarkdownToPDF.

func ReadAFile

func ReadAFile(file_to_read string) string

ReadAFile is a convenience function. Given a filename string, reads the file and passes it back to the calling function as a string. Given a "-" switch the function will read from stdin rather than from a file.

func SetTheHeaders

func SetTheHeaders(contents string, parameters map[string]string) map[string]*Header

SetTheHeaders is the primary parser of structured headers. It parses the styles and header structure and establishes a map of triggers and Header structs delimiting the structured headers.

It begins by parsing the "level-style" parameter to determine if the original style "llll." headers are used by the template or if the new style headers "l4." are used.

Second the function parses the "no-indent" parameter to determine which of the headers are not to be indented. These are put into a slice.

Third it parses the "no-reset" parameter to determine which of the headers are not to be reset. These are also put into a slice.

Finally the function calls the main parsing function "parseHeaders" which returns the map of structs and triggers for each of the relevant headers by the parser. This map is what is returned to the calling function.

func WriteToPdf

func WriteToPdf(contents string, outputFile string)

WriteToPdf sends a maruku flavor markdown file to a hosted webservice which will build that file into a pdf. The returned file is then saved to the appropriate location as passed by the outputFile parameter.

Thanks for the help: @attila-o && @burfl from Stack Overflow, per ... http://stackoverflow.com/questions/20205796/golang-post-data-using-the-content-type-multipart-form-data and http://stackoverflow.com/questions/16311232/how-to-pipe-http-response-to-a-file-in-golang

func WriteToPdfRaw

func WriteToPdfRaw(contents string) string

Types

type Header struct {
	// contains filtered or unexported fields
}

Header is the primary type which establishes how the structured headers will be parsed. Trigger is the string at the beginning of the line in the parsing block which triggers this header. Reset is a boolean which lets the parser know whether this header is to be reset or not. Level Number is an integer of which level of the header this particular header is. Indent is the number of spaces which the header should be indented. Style is pulled from the case switch in the defineHeaderStyle function. ResetVal is the value which the header is reset to -- this is always the value which the header is initiated to. BeforeVal is the string which is placed before the currrent value. CurrtVal is the current value of the header which is iterated as the tree parser performs its work. AfterVal is the string which goes after the currtVal -- typically it is only one char.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL