diff --git a/doc/Cache.html b/doc/Cache.html index 91f87d5..e3eac84 100644 --- a/doc/Cache.html +++ b/doc/Cache.html @@ -1,2 +1,2 @@ -8.1 Cache
Module reference
8.1 Cache
8.2 Decode
8.3 File
8.4 Pagetree
8.5 Render
8.6 Template
8.7 Tag
8.8 Top
8.9 World
On this page:
current-cache
cached-require
make-cache
reset-cache
cache-ref
6.0.1.6

8.1 Cache

 (require pollen/cache) package: pollen

The slowest part of a render is parsing and decoding the source file. Often, previewing a single source file necessarily means decoding others (for instance templates, or other source files that are linked into the main source file). But usually, only one source file is changing at a time. Therefore, Pollen stores copies of the exports of source files — namely, whatever is stored in doc and metas — in the cache so they can be reused.

parameter

(current-cache)  hash?

(current-cache hash)  void?
  hash : hash?
 = (make-cache)
A parameter that refers to the current cache. It is initialized with make-cache.

The cache is a hash table that uses the complete path of a source file as its keys. The value associated with each of these keys is a subcache — another hash table with keys 'doc, 'metas (for storing the exports of the source file) and 'mod-time (for storing the modification time, provided by file-or-directory-modify-seconds).

procedure

(cached-require source-path key)  (or/c txexpr? hash? integer?)

  source-path : pathish?
  key : (or/c 'doc 'metas 'mod-time)
Similar to (dynamic-require source-path key), except that it first tries to retrieve the requested value out of current-cache. If it’s not there, or out of date, dynamic-require is used to update the value.

The only keys supported are 'doc, 'metas, and 'mod-time.

If you want the speed benefit of the cache, you should always use cached-require to get data from Pollen source files. That doesn’t mean you can’t still use functions like require, local-require, and dynamic-require. They’ll just be slower.

procedure

(make-cache)  hash?

Initializes current-cache.

procedure

(reset-cache)  void?

Clears current-cache. When only the nuclear option will do.

procedure

(cache-ref source-path)  hash?

  source-path : pathish?
Returns the subcache associated with the key source-path, which will itself be a hash table. See current-cache.

 
\ No newline at end of file +8.1 Cache
Module reference
8.1 Cache
8.2 Decode
8.3 File
8.4 Pagetree
8.5 Render
8.6 Template
8.7 Tag
8.8 Top
8.9 World
On this page:
current-cache
cached-require
make-cache
reset-cache
cache-ref
6.0.1.6

8.1 Cache

 (require pollen/cache) package: pollen

The slowest part of a render is parsing and decoding the source file. Often, previewing a single source file necessarily means decoding others (for instance templates, or other source files that are linked into the main source file). But usually, only one source file is changing at a time. Therefore, Pollen stores copies of the exports of source files — namely, whatever is stored in doc and metas — in the cache so they can be reused.

parameter

(current-cache)  hash?

(current-cache hash)  void?
  hash : hash?
A parameter that refers to the current cache. It is initialized with make-cache.

The cache is a hash table that uses the complete path of a source file as its keys. The value associated with each of these keys is a subcache — another hash table with keys 'doc, 'metas (for storing the exports of the source file) and 'mod-time (for storing the modification time, provided by file-or-directory-modify-seconds).

procedure

(cached-require source-path key)  (or/c txexpr? hash? integer?)

  source-path : pathish?
  key : (or/c 'doc 'metas 'mod-time)
Similar to (dynamic-require source-path key), except that it first tries to retrieve the requested value out of current-cache. If it’s not there, or out of date, dynamic-require is used to update the value.

The only keys supported are 'doc, 'metas, and 'mod-time.

If you want the speed benefit of the cache, you should always use cached-require to get data from Pollen source files. That doesn’t mean you can’t still use functions like require, local-require, and dynamic-require. They’ll just be slower.

procedure

(make-cache)  hash?

Initializes current-cache.

procedure

(reset-cache)  void?

Clears current-cache. When only the nuclear option will do.

procedure

(cache-ref source-path)  hash?

  source-path : pathish?
Returns the subcache associated with the key source-path, which will itself be a hash table. See current-cache.

 
\ No newline at end of file diff --git a/doc/Decode.html b/doc/Decode.html index 79b4a79..d3762d9 100644 --- a/doc/Decode.html +++ b/doc/Decode.html @@ -1,2 +1,2 @@ -8.2 Decode
Module reference
8.1 Cache
8.2 Decode
8.3 File
8.4 Pagetree
8.5 Render
8.6 Template
8.7 Tag
8.8 Top
8.9 World
8.2 Decode
On this page:
decode
8.2.1 Block
project-block-tags
register-block-tag
block-txexpr?
8.2.2 Typography
whitespace?
whitespace/  nbsp?
smart-quotes
smart-dashes
detect-linebreaks
detect-paragraphs
6.0.1.6

8.2 Decode

 (require pollen/decode) package: pollen

The doc export of a Pollen markup file is a simple X-expression. Decoding refers to any post-processing of this X-expression. The pollen/decode module provides tools for creating decoders.

The decode step can happen separately from the compilation of the file. But you can also attach a decoder to the markup file’s root node, so the decoding happens automatically when the markup is compiled, and thus automatically incorporated into doc. (Following this approach, you could also attach multiple decoders to different tags within doc.)

You can, of course, embed function calls within Pollen markup. But since markup is optimized for authors, decoding is useful for operations that can or should be moved out of the authoring layer.

One example is presentation and layout. For instance, detect-paragraphs is a decoder function that lets authors mark paragraphs in their source simply by using two carriage returns.

Another example is conversion of output into a particular data format. Most Pollen functions are optimized for HTML output, but one could write a decoder that targets another format.

procedure

(decode tagged-xexpr    
  [#:txexpr-tag-proc txexpr-tag-proc    
  #:txexpr-attrs-proc txexpr-attrs-proc    
  #:txexpr-elements-proc txexpr-elements-proc    
  #:block-txexpr-proc block-txexpr-proc    
  #:inline-txexpr-proc inline-txexpr-proc    
  #:string-proc string-proc    
  #:symbol-proc symbol-proc    
  #:valid-char-proc valid-char-proc    
  #:cdata-proc cdata-proc    
  #:exclude-tags tags-to-exclude])  txexpr?
  tagged-xexpr : txexpr?
  txexpr-tag-proc : (txexpr-tag? . -> . txexpr-tag?)
   = (λ(tag) tag)
  txexpr-attrs-proc : (txexpr-attrs? . -> . txexpr-attrs?)
   = (λ(attrs) attrs)
  txexpr-elements-proc : (txexpr-elements? . -> . txexpr-elements?)
   = (λ(elements) elements)
  block-txexpr-proc : (block-txexpr? . -> . xexpr?) = (λ(tx) tx)
  inline-txexpr-proc : (txexpr? . -> . xexpr?) = (λ(tx) tx)
  string-proc : (string? . -> . xexpr?) = (λ(str) str)
  symbol-proc : (symbol? . -> . xexpr?) = (λ(sym) sym)
  valid-char-proc : (valid-char? . -> . xexpr?) = (λ(vc) vc)
  cdata-proc : (cdata? . -> . xexpr?) = (λ(cdata) cdata)
  tags-to-exclude : (listof symbol?) = null
Recursively process a tagged-xexpr, usually the one exported from a Pollen source file as doc.

This function doesn’t do much on its own. Rather, it provides the hooks upon which harder-working functions can be hung.

Recall from [future link: Pollen mechanics] that any tag can have a function attached to it. By default, the tagged-xexpr from a source file is tagged with root. So the typical way to use decode is to attach your decoding functions to it, and then define root to invoke your decode function. Then it will be automatically applied to every doc during compile.

For instance, here’s how decode is attached to root in Butterick’s Practical Typography. There’s not much to it —

[update with actual code]

This illustrates another important point: even though decode presents an imposing list of arguments, you’re unlikely to use all of them at once. These represent possibilities, not requirements. For instance, let’s see what happens when decode is invoked without any of its optional arguments.

Examples:

> (define tx '(root "I wonder" (em "why") "this works."))
> (decode tx)

'(root "I wonder" (em "why") "this works.")

Right — nothing. That’s because the default value for the decoding arguments is the identity function, (λ (x) x). So all the input gets passed through intact unless another action is specified.

The *-proc arguments of decode take procedures that are applied to specific categories of elements within txexpr.

The txexpr-tag-proc argument is a procedure that handles X-expression tags.

Examples:

> (define tx '(p "I'm from a strange" (strong "namespace")))
; Tags are symbols, so a tag-proc should return a symbol
> (decode tx #:txexpr-tag-proc (λ(t) (string->symbol (format "ns:~a" t))))

'(ns:p "I'm from a strange" (ns:strong "namespace"))

The txexpr-attrs-proc argument is a procedure that handles lists of X-expression attributes. (The txexpr module, included at no extra charge with Pollen, includes useful helper functions for dealing with these attribute lists.)

Examples:

> (define tx '(p [[id "first"]] "If I only had a brain."))
; Attrs is a list, so cons is OK for simple cases
> (decode tx #:txexpr-attrs-proc (λ(attrs) (cons '[class "PhD"] attrs)))

'(p ((class "PhD") (id "first")) "If I only had a brain.")

Note that txexpr-attrs-proc will change the attributes of every tagged X-expression, even those that don’t have attributes. This is useful, because sometimes you want to add attributes where none existed before. But be careful, because the behavior may make your processing function overinclusive.

Examples:

> (define tx '(div (p [[id "first"]] "If I only had a brain.")
  (p "Me too.")))
; This will insert the new attribute everywhere
> (decode tx #:txexpr-attrs-proc (λ(attrs) (cons '[class "PhD"] attrs)))

'(div

  ((class "PhD"))

  (p ((class "PhD") (id "first")) "If I only had a brain.")

  (p ((class "PhD")) "Me too."))

; This will add the new attribute only to non-null attribute lists
> (decode tx #:txexpr-attrs-proc
  (λ(attrs) (if (null? attrs) attrs (cons '[class "PhD"] attrs))))

'(div (p ((class "PhD") (id "first")) "If I only had a brain.") (p "Me too."))

The txexpr-elements-proc argument is a procedure that operates on the list of elements that represents the content of each tagged X-expression. Note that each element of an X-expression is subject to two passes through the decoder: once now, as a member of the list of elements, and also later, through its type-specific decoder (i.e., string-proc, symbol-proc, and so on).

Examples:

> (define tx '(div "Double" "\n" "toil" amp "trouble"))
; Every element gets doubled ...
> (decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) `(,e ,e)) es)))

'(div "Double" "Double" "\n" "\n" "toil" "toil" amp amp "trouble" "trouble")

; ... but only strings get capitalized
> (decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) `(,e ,e)) es))
  #:string-proc (λ(s) (string-upcase s)))

'(div "DOUBLE" "DOUBLE" "\n" "\n" "TOIL" "TOIL" amp amp "TROUBLE" "TROUBLE")

So why do you need txexpr-elements-proc? Because some types of element decoding depend on context, thus it’s necessary to handle the elements as a group. For instance, the doubling function above, though useless, requires handling the element list as a whole, because elements are being added.

A more useful example: paragraph detection. The behavior is not merely a map across each element:

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
; Context matters. Trailing whitespace is ignored ...
> (paras '(body "The first paragraph." "\n\n"))

'(body "The first paragraph.")

; ... but whitespace between strings is converted to a break.
> (paras '(body "The first paragraph." "\n\n" "And another."))

'(body (p "The first paragraph.") (p "And another."))

; A combination of both types
> (paras '(body "The first paragraph." "\n\n" "And another." "\n\n"))

'(body (p "The first paragraph.") (p "And another."))

The block-txexpr-proc argument and the inline-txexpr-proc arguments are procedures that operate on tagged X-expressions. If the X-expression meets the block-txexpr? test, it is processed by block-txexpr-proc. Otherwise, it is processed by inline-txexpr-proc. Thus every tagged X-expression will be handled by one or the other. Of course, if you want block and inline elements to be handled the same way, you can set block-txexpr-proc and inline-txexpr-proc to be the same procedure.

Examples:

> (define tx '(div "Please" (em "mind the gap") (h1 "Tuesdays only")))
> (define add-ns (λ(tx) (make-txexpr
      (string->symbol (format "ns:~a" (get-tag tx)))
      (get-attrs tx)
      (get-elements tx))))
; div and h1 are block elements, so this will only affect them
> (decode tx #:block-txexpr-proc add-ns)

'(ns:div "Please" (em "mind the gap") (ns:h1 "Tuesdays only"))

; em is an inline element, so this will only affect it
> (decode tx #:inline-txexpr-proc add-ns)

'(div "Please" (ns:em "mind the gap") (h1 "Tuesdays only"))

; this will affect all elements
> (decode tx #:block-txexpr-proc add-ns #:inline-txexpr-proc add-ns)

'(ns:div "Please" (ns:em "mind the gap") (ns:h1 "Tuesdays only"))

The string-proc, symbol-proc, valid-char-proc, and cdata-proc arguments are procedures that operate on X-expressions that are strings, symbols, valid-chars, and CDATA, respectively. Deliberately, the output contracts for these procedures accept any kind of X-expression (meaning, the procedure can change the X-expression type).

Examples:

; A div with string, entity, character, and cdata elements
> (define tx `(div "Moe" amp 62 ,(cdata #f #f "3 > 2;")))
> (define rulify (λ(x) '(hr)))
; The rulify function is selectively applied to each
> (print (decode tx #:string-proc rulify))

'(div (hr) amp 62 #(struct:cdata #f #f "3 > 2;"))

> (print (decode tx #:symbol-proc rulify))

'(div "Moe" (hr) 62 #(struct:cdata #f #f "3 > 2;"))

> (print (decode tx #:valid-char-proc rulify))

'(div "Moe" amp (hr) #(struct:cdata #f #f "3 > 2;"))

> (print (decode tx #:cdata-proc rulify))

'(div "Moe" amp 62 (hr))

Finally, the tags-to-exclude argument is a list of tags that will be exempted from decoding. Though you could get the same result by testing the input within the individual decoding functions, that’s tedious and potentially slower.

Examples:

> (define tx '(p "I really think" (em "italics") "should be lowercase."))
> (decode tx #:string-proc (λ(s) (string-upcase s)))

'(p "I REALLY THINK" (em "ITALICS") "SHOULD BE LOWERCASE.")

> (decode tx #:string-proc (λ(s) (string-upcase s)) #:exclude-tags '(em))

'(p "I REALLY THINK" (em "italics") "SHOULD BE LOWERCASE.")

The tags-to-exclude argument is useful if you’re decoding source that’s destined to become HTML. According to the HTML spec, material within a <style> or <script> block needs to be preserved literally. In this example, if the CSS and JavaScript blocks are capitalized, they won’t work. So exclude '(style script), and problem solved.

Examples:

> (define tx '(body (h1 [[class "Red"]] "Let's visit Planet Telex.")
  (style [[type "text/css"]] ".Red {color: green;}")
  (script [[type "text/javascript"]] "var area = h * w;")))
> (decode tx #:string-proc (λ(s) (string-upcase s)))

'(body

  (h1 ((class "Red")) "LET'S VISIT PLANET TELEX.")

  (style ((type "text/css")) ".RED {COLOR: GREEN;}")

  (script ((type "text/javascript")) "VAR AREA = H * W;"))

> (decode tx #:string-proc (λ(s) (string-upcase s))
  #:exclude-tags '(style script))

'(body

  (h1 ((class "Red")) "LET'S VISIT PLANET TELEX.")

  (style ((type "text/css")) ".Red {color: green;}")

  (script ((type "text/javascript")) "var area = h * w;"))

8.2.1 Block

Because it’s convenient, Pollen categorizes tagged X-expressions into two categories: block and inline. Why is it convenient? When using decode, you often want to treat the two categories differently. Not that you have to. But this is how you can.

parameter

(project-block-tags)  (listof txexpr-tag?)

(project-block-tags block-tags)  void?
  block-tags : (listof txexpr-tag?)
 = (listof symbol?)
A parameter that defines the set of tags that decode will treat as blocks. This parameter is initialized with the HTML block tags, namely:

(address article aside audio blockquote body canvas dd div dl fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hgroup noscript ol output p pre section table tfoot ul video)

procedure

(register-block-tag tag)  void?

  tag : txexpr-tag?
Adds a tag to project-block-tags so that block-txexpr? will report it as a block, and decode will process it with block-txexpr-proc rather than inline-txexpr-proc.

Pollen tries to do the right thing without being told. But this is the rare case where you have to be explicit. If you introduce a tag into your markup that you want treated as a block, you must use this function to identify it, or you will get spooky behavior later on.

For instance, detect-paragraphs knows that block elements in the markup shouldn’t be wrapped in a p tag. So if you introduce a new block element called bloq without registering it as a block, misbehavior will follow:

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
> (paras '(body "I want to be a paragraph." "\n\n" (bloq "But not me.")))

'(body (p "I want to be a paragraph.") (p (bloq "But not me.")))

; Wrong: bloq should not be wrapped

But once you register bloq as a block, order is restored:

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
> (register-block-tag 'bloq)
> (paras '(body "I want to be a paragraph." "\n\n" (bloq "But not me.")))

'(body (p "I want to be a paragraph.") (bloq "But not me."))

; Right: bloq is treated as a block

If you find the idea of registering block tags unbearable, good news. The project-block-tags include the standard HTML block tags by default. So if you just want to use things like div and p and h1–h6, you’ll get the right behavior for free.

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
> (paras '(body "I want to be a paragraph." "\n\n" (div "But not me.")))

'(body (p "I want to be a paragraph.") (div "But not me."))

procedure

(block-txexpr? v)  boolean?

  v : any/c
Predicate that tests whether v is a tagged X-expression, and if so, whether the tag is among the project-block-tags. If not, it is treated as inline. To adjust how this test works, use register-block-tag.

8.2.2 Typography

An assortment of typography & layout functions, designed to be used with decode. These aren’t hard to write. So if you like these, use them. If not, make your own.

procedure

(whitespace? v)  boolean?

  v : any/c
A predicate that returns #t for any stringlike v that’s entirely whitespace, but also the empty string, as well as lists and vectors that are made only of whitespace? members. Following the regexp-match convention, whitespace? does not return #t for a nonbreaking space. If you prefer that behavior, use whitespace/nbsp?.

Examples:

> (whitespace? "\n\n   ")

#t

> (whitespace? (string->symbol "\n\n   "))

#t

> (whitespace? "")

#t

> (whitespace? '("" "  " "\n\n\n" " \n"))

#t

> (define nonbreaking-space (format "~a" #\u00A0))
> (whitespace? nonbreaking-space)

#f

procedure

(whitespace/nbsp? v)  boolean?

  v : any/c
Like whitespace?, but also returns #t for nonbreaking spaces.

Examples:

> (whitespace/nbsp? "\n\n   ")

#t

> (whitespace/nbsp? (string->symbol "\n\n   "))

#t

> (whitespace/nbsp? "")

#t

> (whitespace/nbsp? '("" "  " "\n\n\n" " \n"))

#t

> (define nonbreaking-space (format "~a" #\u00A0))
> (whitespace/nbsp? nonbreaking-space)

#t

procedure

(smart-quotes str)  string?

  str : string?
Convert straight quotes in str to curly according to American English conventions.

Examples:

> (define tricky-string
  "\"Why,\" she could've asked, \"are we in O‘ahu watching 'Mame'?\"")
> (display tricky-string)

"Why," she could've asked, "are we in O‘ahu watching 'Mame'?"

> (display (smart-quotes tricky-string))

“Why,” she could’ve asked, “are we in O‘ahu watching ‘Mame’?”

procedure

(smart-dashes str)  string?

  str : string?
In str, convert three hyphens to an em dash, and two hyphens to an en dash, and remove surrounding spaces.

Examples:

> (define tricky-string "I had a few --- OK, like 6--8 --- thin mints.")
> (display tricky-string)

I had a few --- OK, like 6--8 --- thin mints.

> (display (smart-dashes tricky-string))

I had a few—OK, like 6–8—thin mints.

; Monospaced font not great for showing dashes, but you get the idea

procedure

(detect-linebreaks tagged-xexpr-elements 
  [#:separator linebreak-sep 
  #:insert linebreak]) 
  txexpr-elements?
  tagged-xexpr-elements : txexpr-elements?
  linebreak-sep : string? = world:linebreak-separator
  linebreak : xexpr? = '(br)
Within tagged-xexpr-elements, convert occurrences of linebreak-sep ("\n" by default) to linebreak, but only if linebreak-sep does not occur between blocks (see block-txexpr?). Why? Because block-level elements automatically display on a new line, so adding linebreak would be superfluous. In that case, linebreak-sep just disappears.

Examples:

> (detect-linebreaks '(div "Two items:" "\n" (em "Eggs") "\n" (em "Bacon")))

'(div "Two items:" (br) (em "Eggs") (br) (em "Bacon"))

> (detect-linebreaks '(div "Two items:" "\n" (div "Eggs") "\n" (div "Bacon")))

'(div "Two items:" (div "Eggs") (div "Bacon"))

procedure

(detect-paragraphs elements 
  [#:separator paragraph-sep 
  #:tag paragraph-tag 
  #:linebreak-proc linebreak-proc]) 
  txexpr-elements?
  elements : txexpr-elements?
  paragraph-sep : string? = world:paragraph-separator
  paragraph-tag : symbol? = 'p
  linebreak-proc : (txexpr-elements? . -> . txexpr-elements?)
   = detect-linebreaks
Find paragraphs within elements, as denoted by paragraph-sep, and wrap them with paragraph-tag, unless the element is already a block-txexpr? (because in that case, the wrapping is superfluous). Thus, as a consequence, if paragraph-sep occurs between two blocks, it’s ignored.

The paragraph-tag argument sets the tag used to wrap paragraphs.

The linebreak-proc argument allows you to use a different linebreaking procedure other than the usual detect-linebreaks.

Examples:

> (detect-paragraphs '("First para" "\n\n" "Second para"))

'((p "First para") (p "Second para"))

> (detect-paragraphs '("First para" "\n\n" "Second para" "\n" "Second line"))

'((p "First para") (p "Second para" (br) "Second line"))

> (detect-paragraphs '("First para" "\n\n" (div "Second block")))

'((p "First para") (div "Second block"))

> (detect-paragraphs '((div "First block") "\n\n" (div "Second block")))

'((div "First block") (div "Second block"))

> (detect-paragraphs '("First para" "\n\n" "Second para") #:tag 'ns:p)

'((ns:p "First para") (ns:p "Second para"))

> (detect-paragraphs '("First para" "\n\n" "Second para" "\n" "Second line")
  #:linebreak-proc (λ(x) (detect-linebreaks x #:insert '(newline))))

'((p "First para") (p "Second para" (newline) "Second line"))

 
\ No newline at end of file +8.2 Decode
Module reference
8.1 Cache
8.2 Decode
8.3 File
8.4 Pagetree
8.5 Render
8.6 Template
8.7 Tag
8.8 Top
8.9 World
8.2 Decode
On this page:
decode
8.2.1 Block
project-block-tags
register-block-tag
block-txexpr?
8.2.2 Typography
whitespace?
whitespace/  nbsp?
smart-quotes
smart-dashes
detect-linebreaks
detect-paragraphs
6.0.1.6

8.2 Decode

 (require pollen/decode) package: pollen

The doc export of a Pollen markup file is a simple X-expression. Decoding refers to any post-processing of this X-expression. The pollen/decode module provides tools for creating decoders.

The decode step can happen separately from the compilation of the file. But you can also attach a decoder to the markup file’s root node, so the decoding happens automatically when the markup is compiled, and thus automatically incorporated into doc. (Following this approach, you could also attach multiple decoders to different tags within doc.)

You can, of course, embed function calls within Pollen markup. But since markup is optimized for authors, decoding is useful for operations that can or should be moved out of the authoring layer.

One example is presentation and layout. For instance, detect-paragraphs is a decoder function that lets authors mark paragraphs in their source simply by using two carriage returns.

Another example is conversion of output into a particular data format. Most Pollen functions are optimized for HTML output, but one could write a decoder that targets another format.

procedure

(decode tagged-xexpr    
  [#:txexpr-tag-proc txexpr-tag-proc    
  #:txexpr-attrs-proc txexpr-attrs-proc    
  #:txexpr-elements-proc txexpr-elements-proc    
  #:block-txexpr-proc block-txexpr-proc    
  #:inline-txexpr-proc inline-txexpr-proc    
  #:string-proc string-proc    
  #:symbol-proc symbol-proc    
  #:valid-char-proc valid-char-proc    
  #:cdata-proc cdata-proc    
  #:exclude-tags tags-to-exclude])  txexpr?
  tagged-xexpr : txexpr?
  txexpr-tag-proc : (txexpr-tag? . -> . txexpr-tag?)
   = (λ(tag) tag)
  txexpr-attrs-proc : (txexpr-attrs? . -> . txexpr-attrs?)
   = (λ(attrs) attrs)
  txexpr-elements-proc : (txexpr-elements? . -> . txexpr-elements?)
   = (λ(elements) elements)
  block-txexpr-proc : (block-txexpr? . -> . xexpr?) = (λ(tx) tx)
  inline-txexpr-proc : (txexpr? . -> . xexpr?) = (λ(tx) tx)
  string-proc : (string? . -> . xexpr?) = (λ(str) str)
  symbol-proc : (symbol? . -> . xexpr?) = (λ(sym) sym)
  valid-char-proc : (valid-char? . -> . xexpr?) = (λ(vc) vc)
  cdata-proc : (cdata? . -> . xexpr?) = (λ(cdata) cdata)
  tags-to-exclude : (listof symbol?) = null
Recursively process a tagged-xexpr, usually the one exported from a Pollen source file as doc.

This function doesn’t do much on its own. Rather, it provides the hooks upon which harder-working functions can be hung.

Recall from [future link: Pollen mechanics] that any tag can have a function attached to it. By default, the tagged-xexpr from a source file is tagged with root. So the typical way to use decode is to attach your decoding functions to it, and then define root to invoke your decode function. Then it will be automatically applied to every doc during compile.

For instance, here’s how decode is attached to root in Butterick’s Practical Typography. There’s not much to it —

[update with actual code]

This illustrates another important point: even though decode presents an imposing list of arguments, you’re unlikely to use all of them at once. These represent possibilities, not requirements. For instance, let’s see what happens when decode is invoked without any of its optional arguments.

Examples:

> (define tx '(root "I wonder" (em "why") "this works."))
> (decode tx)

'(root "I wonder" (em "why") "this works.")

Right — nothing. That’s because the default value for the decoding arguments is the identity function, (λ (x) x). So all the input gets passed through intact unless another action is specified.

The *-proc arguments of decode take procedures that are applied to specific categories of elements within txexpr.

The txexpr-tag-proc argument is a procedure that handles X-expression tags.

Examples:

> (define tx '(p "I'm from a strange" (strong "namespace")))
; Tags are symbols, so a tag-proc should return a symbol
> (decode tx #:txexpr-tag-proc (λ(t) (string->symbol (format "ns:~a" t))))

'(ns:p "I'm from a strange" (ns:strong "namespace"))

The txexpr-attrs-proc argument is a procedure that handles lists of X-expression attributes. (The txexpr module, included at no extra charge with Pollen, includes useful helper functions for dealing with these attribute lists.)

Examples:

> (define tx '(p [[id "first"]] "If I only had a brain."))
; Attrs is a list, so cons is OK for simple cases
> (decode tx #:txexpr-attrs-proc (λ(attrs) (cons '[class "PhD"] attrs)))

'(p ((class "PhD") (id "first")) "If I only had a brain.")

Note that txexpr-attrs-proc will change the attributes of every tagged X-expression, even those that don’t have attributes. This is useful, because sometimes you want to add attributes where none existed before. But be careful, because the behavior may make your processing function overinclusive.

Examples:

> (define tx '(div (p [[id "first"]] "If I only had a brain.")
  (p "Me too.")))
; This will insert the new attribute everywhere
> (decode tx #:txexpr-attrs-proc (λ(attrs) (cons '[class "PhD"] attrs)))

'(div

  ((class "PhD"))

  (p ((class "PhD") (id "first")) "If I only had a brain.")

  (p ((class "PhD")) "Me too."))

; This will add the new attribute only to non-null attribute lists
> (decode tx #:txexpr-attrs-proc
  (λ(attrs) (if (null? attrs) attrs (cons '[class "PhD"] attrs))))

'(div (p ((class "PhD") (id "first")) "If I only had a brain.") (p "Me too."))

The txexpr-elements-proc argument is a procedure that operates on the list of elements that represents the content of each tagged X-expression. Note that each element of an X-expression is subject to two passes through the decoder: once now, as a member of the list of elements, and also later, through its type-specific decoder (i.e., string-proc, symbol-proc, and so on).

Examples:

> (define tx '(div "Double" "\n" "toil" amp "trouble"))
; Every element gets doubled ...
> (decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) `(,e ,e)) es)))

'(div "Double" "Double" "\n" "\n" "toil" "toil" amp amp "trouble" "trouble")

; ... but only strings get capitalized
> (decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) `(,e ,e)) es))
  #:string-proc (λ(s) (string-upcase s)))

'(div "DOUBLE" "DOUBLE" "\n" "\n" "TOIL" "TOIL" amp amp "TROUBLE" "TROUBLE")

So why do you need txexpr-elements-proc? Because some types of element decoding depend on context, thus it’s necessary to handle the elements as a group. For instance, the doubling function above, though useless, requires handling the element list as a whole, because elements are being added.

A more useful example: paragraph detection. The behavior is not merely a map across each element:

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
; Context matters. Trailing whitespace is ignored ...
> (paras '(body "The first paragraph." "\n\n"))

'(body "The first paragraph.")

; ... but whitespace between strings is converted to a break.
> (paras '(body "The first paragraph." "\n\n" "And another."))

'(body (p "The first paragraph.") (p "And another."))

; A combination of both types
> (paras '(body "The first paragraph." "\n\n" "And another." "\n\n"))

'(body (p "The first paragraph.") (p "And another."))

The block-txexpr-proc argument and the inline-txexpr-proc arguments are procedures that operate on tagged X-expressions. If the X-expression meets the block-txexpr? test, it is processed by block-txexpr-proc. Otherwise, it is processed by inline-txexpr-proc. Thus every tagged X-expression will be handled by one or the other. Of course, if you want block and inline elements to be handled the same way, you can set block-txexpr-proc and inline-txexpr-proc to be the same procedure.

Examples:

> (define tx '(div "Please" (em "mind the gap") (h1 "Tuesdays only")))
> (define add-ns (λ(tx) (make-txexpr
      (string->symbol (format "ns:~a" (get-tag tx)))
      (get-attrs tx)
      (get-elements tx))))
; div and h1 are block elements, so this will only affect them
> (decode tx #:block-txexpr-proc add-ns)

'(ns:div "Please" (em "mind the gap") (ns:h1 "Tuesdays only"))

; em is an inline element, so this will only affect it
> (decode tx #:inline-txexpr-proc add-ns)

'(div "Please" (ns:em "mind the gap") (h1 "Tuesdays only"))

; this will affect all elements
> (decode tx #:block-txexpr-proc add-ns #:inline-txexpr-proc add-ns)

'(ns:div "Please" (ns:em "mind the gap") (ns:h1 "Tuesdays only"))

The string-proc, symbol-proc, valid-char-proc, and cdata-proc arguments are procedures that operate on X-expressions that are strings, symbols, valid-chars, and CDATA, respectively. Deliberately, the output contracts for these procedures accept any kind of X-expression (meaning, the procedure can change the X-expression type).

Examples:

; A div with string, entity, character, and cdata elements
> (define tx `(div "Moe" amp 62 ,(cdata #f #f "3 > 2;")))
> (define rulify (λ(x) '(hr)))
; The rulify function is selectively applied to each
> (print (decode tx #:string-proc rulify))

'(div (hr) amp 62 #(struct:cdata #f #f "3 > 2;"))

> (print (decode tx #:symbol-proc rulify))

'(div "Moe" (hr) 62 #(struct:cdata #f #f "3 > 2;"))

> (print (decode tx #:valid-char-proc rulify))

'(div "Moe" amp (hr) #(struct:cdata #f #f "3 > 2;"))

> (print (decode tx #:cdata-proc rulify))

'(div "Moe" amp 62 (hr))

Finally, the tags-to-exclude argument is a list of tags that will be exempted from decoding. Though you could get the same result by testing the input within the individual decoding functions, that’s tedious and potentially slower.

Examples:

> (define tx '(p "I really think" (em "italics") "should be lowercase."))
> (decode tx #:string-proc (λ(s) (string-upcase s)))

'(p "I REALLY THINK" (em "ITALICS") "SHOULD BE LOWERCASE.")

> (decode tx #:string-proc (λ(s) (string-upcase s)) #:exclude-tags '(em))

'(p "I REALLY THINK" (em "italics") "SHOULD BE LOWERCASE.")

The tags-to-exclude argument is useful if you’re decoding source that’s destined to become HTML. According to the HTML spec, material within a <style> or <script> block needs to be preserved literally. In this example, if the CSS and JavaScript blocks are capitalized, they won’t work. So exclude '(style script), and problem solved.

Examples:

> (define tx '(body (h1 [[class "Red"]] "Let's visit Planet Telex.")
  (style [[type "text/css"]] ".Red {color: green;}")
  (script [[type "text/javascript"]] "var area = h * w;")))
> (decode tx #:string-proc (λ(s) (string-upcase s)))

'(body

  (h1 ((class "Red")) "LET'S VISIT PLANET TELEX.")

  (style ((type "text/css")) ".RED {COLOR: GREEN;}")

  (script ((type "text/javascript")) "VAR AREA = H * W;"))

> (decode tx #:string-proc (λ(s) (string-upcase s))
  #:exclude-tags '(style script))

'(body

  (h1 ((class "Red")) "LET'S VISIT PLANET TELEX.")

  (style ((type "text/css")) ".Red {color: green;}")

  (script ((type "text/javascript")) "var area = h * w;"))

8.2.1 Block

Because it’s convenient, Pollen categorizes tagged X-expressions into two categories: block and inline. Why is it convenient? When using decode, you often want to treat the two categories differently. Not that you have to. But this is how you can.

parameter

(project-block-tags)  (listof txexpr-tag?)

(project-block-tags block-tags)  void?
  block-tags : (listof txexpr-tag?)
A parameter that defines the set of tags that decode will treat as blocks. This parameter is initialized with the HTML block tags, namely:

(address article aside audio blockquote body canvas dd div dl fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hgroup noscript ol output p pre section table tfoot ul video)

procedure

(register-block-tag tag)  void?

  tag : txexpr-tag?
Adds a tag to project-block-tags so that block-txexpr? will report it as a block, and decode will process it with block-txexpr-proc rather than inline-txexpr-proc.

Pollen tries to do the right thing without being told. But this is the rare case where you have to be explicit. If you introduce a tag into your markup that you want treated as a block, you must use this function to identify it, or you will get spooky behavior later on.

For instance, detect-paragraphs knows that block elements in the markup shouldn’t be wrapped in a p tag. So if you introduce a new block element called bloq without registering it as a block, misbehavior will follow:

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
> (paras '(body "I want to be a paragraph." "\n\n" (bloq "But not me.")))

'(body (p "I want to be a paragraph.") (p (bloq "But not me.")))

; Wrong: bloq should not be wrapped

But once you register bloq as a block, order is restored:

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
> (register-block-tag 'bloq)
> (paras '(body "I want to be a paragraph." "\n\n" (bloq "But not me.")))

'(body (p "I want to be a paragraph.") (bloq "But not me."))

; Right: bloq is treated as a block

If you find the idea of registering block tags unbearable, good news. The project-block-tags include the standard HTML block tags by default. So if you just want to use things like div and p and h1–h6, you’ll get the right behavior for free.

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
> (paras '(body "I want to be a paragraph." "\n\n" (div "But not me.")))

'(body (p "I want to be a paragraph.") (div "But not me."))

procedure

(block-txexpr? v)  boolean?

  v : any/c
Predicate that tests whether v is a tagged X-expression, and if so, whether the tag is among the project-block-tags. If not, it is treated as inline. To adjust how this test works, use register-block-tag.

8.2.2 Typography

An assortment of typography & layout functions, designed to be used with decode. These aren’t hard to write. So if you like these, use them. If not, make your own.

procedure

(whitespace? v)  boolean?

  v : any/c
A predicate that returns #t for any stringlike v that’s entirely whitespace, but also the empty string, as well as lists and vectors that are made only of whitespace? members. Following the regexp-match convention, whitespace? does not return #t for a nonbreaking space. If you prefer that behavior, use whitespace/nbsp?.

Examples:

> (whitespace? "\n\n   ")

#t

> (whitespace? (string->symbol "\n\n   "))

#t

> (whitespace? "")

#t

> (whitespace? '("" "  " "\n\n\n" " \n"))

#t

> (define nonbreaking-space (format "~a" #\u00A0))
> (whitespace? nonbreaking-space)

#f

procedure

(whitespace/nbsp? v)  boolean?

  v : any/c
Like whitespace?, but also returns #t for nonbreaking spaces.

Examples:

> (whitespace/nbsp? "\n\n   ")

#t

> (whitespace/nbsp? (string->symbol "\n\n   "))

#t

> (whitespace/nbsp? "")

#t

> (whitespace/nbsp? '("" "  " "\n\n\n" " \n"))

#t

> (define nonbreaking-space (format "~a" #\u00A0))
> (whitespace/nbsp? nonbreaking-space)

#t

procedure

(smart-quotes str)  string?

  str : string?
Convert straight quotes in str to curly according to American English conventions.

Examples:

> (define tricky-string
  "\"Why,\" she could've asked, \"are we in O‘ahu watching 'Mame'?\"")
> (display tricky-string)

"Why," she could've asked, "are we in O‘ahu watching 'Mame'?"

> (display (smart-quotes tricky-string))

“Why,” she could’ve asked, “are we in O‘ahu watching ‘Mame’?”

procedure

(smart-dashes str)  string?

  str : string?
In str, convert three hyphens to an em dash, and two hyphens to an en dash, and remove surrounding spaces.

Examples:

> (define tricky-string "I had a few --- OK, like 6--8 --- thin mints.")
> (display tricky-string)

I had a few --- OK, like 6--8 --- thin mints.

> (display (smart-dashes tricky-string))

I had a few—OK, like 6–8—thin mints.

; Monospaced font not great for showing dashes, but you get the idea

procedure

(detect-linebreaks tagged-xexpr-elements 
  [#:separator linebreak-sep 
  #:insert linebreak]) 
  txexpr-elements?
  tagged-xexpr-elements : txexpr-elements?
  linebreak-sep : string? = world:linebreak-separator
  linebreak : xexpr? = '(br)
Within tagged-xexpr-elements, convert occurrences of linebreak-sep ("\n" by default) to linebreak, but only if linebreak-sep does not occur between blocks (see block-txexpr?). Why? Because block-level elements automatically display on a new line, so adding linebreak would be superfluous. In that case, linebreak-sep just disappears.

Examples:

> (detect-linebreaks '(div "Two items:" "\n" (em "Eggs") "\n" (em "Bacon")))

'(div "Two items:" (br) (em "Eggs") (br) (em "Bacon"))

> (detect-linebreaks '(div "Two items:" "\n" (div "Eggs") "\n" (div "Bacon")))

'(div "Two items:" (div "Eggs") (div "Bacon"))

procedure

(detect-paragraphs elements 
  [#:separator paragraph-sep 
  #:tag paragraph-tag 
  #:linebreak-proc linebreak-proc]) 
  txexpr-elements?
  elements : txexpr-elements?
  paragraph-sep : string? = world:paragraph-separator
  paragraph-tag : symbol? = 'p
  linebreak-proc : (txexpr-elements? . -> . txexpr-elements?)
   = detect-linebreaks
Find paragraphs within elements, as denoted by paragraph-sep, and wrap them with paragraph-tag, unless the element is already a block-txexpr? (because in that case, the wrapping is superfluous). Thus, as a consequence, if paragraph-sep occurs between two blocks, it’s ignored.

The paragraph-tag argument sets the tag used to wrap paragraphs.

The linebreak-proc argument allows you to use a different linebreaking procedure other than the usual detect-linebreaks.

Examples:

> (detect-paragraphs '("First para" "\n\n" "Second para"))

'((p "First para") (p "Second para"))

> (detect-paragraphs '("First para" "\n\n" "Second para" "\n" "Second line"))

'((p "First para") (p "Second para" (br) "Second line"))

> (detect-paragraphs '("First para" "\n\n" (div "Second block")))

'((p "First para") (div "Second block"))

> (detect-paragraphs '((div "First block") "\n\n" (div "Second block")))

'((div "First block") (div "Second block"))

> (detect-paragraphs '("First para" "\n\n" "Second para") #:tag 'ns:p)

'((ns:p "First para") (ns:p "Second para"))

> (detect-paragraphs '("First para" "\n\n" "Second para" "\n" "Second line")
  #:linebreak-proc (λ(x) (detect-linebreaks x #:insert '(newline))))

'((p "First para") (p "Second para" (newline) "Second line"))

 
\ No newline at end of file diff --git a/doc/Pagetree.html b/doc/Pagetree.html index 611a268..806f61f 100644 --- a/doc/Pagetree.html +++ b/doc/Pagetree.html @@ -1,2 +1,2 @@ -8.4 Pagetree
Module reference
8.1 Cache
8.2 Decode
8.3 File
8.4 Pagetree
8.5 Render
8.6 Template
8.7 Tag
8.8 Top
8.9 World
On this page:
pagetree?
validate-pagetree
pagenode?
pagenodeish?
->pagenode
8.4.1 Navigation
current-pagetree
parent
children
siblings
previous
previous*
next
next*
8.4.2 Utilities
pagetree->list
in-pagetree?
path->pagenode
6.0.1.6

8.4 Pagetree

 (require pollen/pagetree) package: pollen

A pagetree is a hierarchical list of Pollen output files. A pagetree source file has the extension .ptree. A pagetree provides a convenient way of separating the structure of the pages from the page sources, and navigating around this structure.

Pagetrees are made of pagenodes. Usually these pagenodes will be names of output files in your project. (If you think it would’ve been more logical to just call them “pages,” perhaps. When I think of a web page, I think of a file on a disk. Whereas pagenodes may — and often do — refer to files that don’t yet exist.)

Books and other long documents are usually organized in a structured way — at minimum they have a sequence of pages, but more often they have sections with subsequences within. Individual Pollen source files don’t know anything about how they’re connected to other files. In theory, you could maintain this information within each source file. This would be a poor use of human energy. Let the pagetree figure it out.

procedure

(pagetree? possible-pagetree)  boolean?

  possible-pagetree : any/c
Test whether possible-pagetree is a valid pagetree. It must be a txexpr? where all elements are pagenode?, and each is unique within possible-pagetree (not counting the root node).

Examples:

> (pagetree? '(root index.html))

#t

> (pagetree? '(root duplicate.html duplicate.html))

#f

> (pagetree? '(root index.html "string.html"))

#f

> (define nested-ptree '(root 1.html 2.html (3.html 3a.html 3b.html)))
> (pagetree? nested-ptree)

#t

> (pagetree? `(root index.html ,nested-ptree (subsection.html more.html)))

#t

; Nesting a subtree twice creates duplication
> (pagetree? `(root index.html ,nested-ptree (subsection.html ,nested-ptree)))

#f

procedure

(validate-pagetree possible-pagetree)  pagetree?

  possible-pagetree : any/c
Like pagetree?, but raises a descriptive error if possible-pagetree is invalid, and otherwise returns possible-pagetree itself.

Examples:

> (validate-pagetree '(root (mama.html son.html daughter.html) uncle.html))

'(root (mama.html son.html daughter.html) uncle.html)

> (validate-pagetree `(root (,+ son.html daughter.html) uncle.html))

#f

> (validate-pagetree '(root (mama.html son.html son.html) mama.html))

validate-pagetree: items aren’t unique: (mama.html son.html)

procedure

(pagenode? possible-pagenode)  boolean?

  possible-pagenode : any/c
Test whether possible-pagenode is a valid pagenode. A pagenode can be any symbol? that is not whitespace/nbsp? Every leaf of a pagetree is a pagenode. In practice, your pagenodes will likely be names of output files.

Pagenodes are symbols (rather than strings) so that pagetrees will be valid tagged X-expressions, which is a more convenient format for validation & processing.

Examples:

; Three symbols, the third one annoying but valid
> (map pagenode? '(symbol index.html |   silly   |))

'(#t #t #t)

; A number, a string, a txexpr, and a whitespace symbol
> (map pagenode? '(9.999 "index.html" (p "Hello") |    |))

'(#f #f #f #f)

procedure

(pagenodeish? v)  boolean?

  v : any/c
Return #t if v can be converted with ->pagenode.

Example:

> (map pagenodeish? '(9.999 "index.html" |    |))

'(#t #t #f)

procedure

(->pagenode v)  pagenode?

  v : pagenodeish?
Convert v to a pagenode.

Examples:

> (map pagenodeish? '(symbol 9.999 "index.html" |  silly  |))

'(#t #t #t #t)

> (map ->pagenode '(symbol 9.999 "index.html" |  silly  |))

'(symbol |9.999| index.html |  silly  |)

8.4.1 Navigation

parameter

(current-pagetree)  pagetree?

(current-pagetree pagetree)  void?
  pagetree : pagetree?
 = #f
A parameter that defines the default pagetree used by pagetree navigation functions (e.g., parent-pagenode, chidren, et al.) if another is not explicitly specified. Initialized to #f.

procedure

(parent p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Find the parent pagenode of p within pagetree. Return #f if there isn’t one.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (parent 'son.html)

'mama.html

> (parent "mama.html")

'root

> (parent (parent 'son.html))

'root

> (parent (parent (parent 'son.html)))

#f

procedure

(children p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Find the child pagenodes of p within pagetree. Return #f if there aren’t any.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (children 'mama.html)

'(son.html daughter.html)

> (children 'uncle.html)

#f

> (children 'root)

'(mama.html uncle.html)

> (map children (children 'root))

'((son.html daughter.html) #f)

procedure

(siblings p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Find the sibling pagenodes of p within pagetree. The list will include p itself. But the function will still return #f if pagetree is #f.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (siblings 'son.html)

'(son.html daughter.html)

> (siblings 'daughter.html)

'(son.html daughter.html)

> (siblings 'mama.html)

'(mama.html uncle.html)

procedure

(previous p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)

procedure

(previous* p [pagetree])  (or/c #f (listof pagenode?))

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Return the pagenode immediately before p. For previous*, return all the pagenodes before p, in sequence. In both cases, return #f if there aren’t any pagenodes. The root pagenode is ignored.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (previous 'daughter.html)

'son.html

> (previous 'son.html)

'mama.html

> (previous (previous 'daughter.html))

'mama.html

> (previous 'mama.html)

#f

> (previous* 'daughter.html)

'(mama.html son.html)

> (previous* 'uncle.html)

'(mama.html son.html daughter.html)

procedure

(next p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)

procedure

(next* p [pagetree])  (or/c #f (listof pagenode?))

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Return the pagenode immediately after p. For next*, return all the pagenodes after p, in sequence. In both cases, return #f if there aren’t any pagenodes. The root pagenode is ignored.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (next 'son.html)

'daughter.html

> (next 'daughter.html)

'uncle.html

> (next (next 'son.html))

'uncle.html

> (next 'uncle.html)

#f

> (next* 'mama.html)

'(son.html daughter.html uncle.html)

> (next* 'daughter.html)

'(uncle.html)

8.4.2 Utilities

procedure

(pagetree->list pagetree)  list?

  pagetree : pagetree?
Convert pagetree to a simple list. Equivalent to a pre-order depth-first traversal of pagetree.

procedure

(in-pagetree? pagenode [pagetree])  boolean?

  pagenode : pagenode?
  pagetree : pagetree? = (current-pagetree)
Report whether pagenode is in pagetree.

procedure

(path->pagenode p)  pagenode?

  p : pathish?
Convert path p to a pagenode — meaning, make it relative to current-project-root, run it through ->output-path, and convert it to a symbol. Does not tell you whether the resultant pagenode actually exists in the current pagetree (for that, use in-pagetree?).

 
\ No newline at end of file +8.4 Pagetree
Module reference
8.1 Cache
8.2 Decode
8.3 File
8.4 Pagetree
8.5 Render
8.6 Template
8.7 Tag
8.8 Top
8.9 World
On this page:
pagetree?
validate-pagetree
pagenode?
pagenodeish?
->pagenode
8.4.1 Navigation
current-pagetree
parent
children
siblings
previous
previous*
next
next*
8.4.2 Utilities
pagetree->list
in-pagetree?
path->pagenode
6.0.1.6

8.4 Pagetree

 (require pollen/pagetree) package: pollen

A pagetree is a hierarchical list of Pollen output files. A pagetree source file has the extension .ptree. A pagetree provides a convenient way of separating the structure of the pages from the page sources, and navigating around this structure.

Pagetrees are made of pagenodes. Usually these pagenodes will be names of output files in your project. (If you think it would’ve been more logical to just call them “pages,” perhaps. When I think of a web page, I think of a file on a disk. Whereas pagenodes may — and often do — refer to files that don’t yet exist.)

Books and other long documents are usually organized in a structured way — at minimum they have a sequence of pages, but more often they have sections with subsequences within. Individual Pollen source files don’t know anything about how they’re connected to other files. In theory, you could maintain this information within each source file. This would be a poor use of human energy. Let the pagetree figure it out.

procedure

(pagetree? possible-pagetree)  boolean?

  possible-pagetree : any/c
Test whether possible-pagetree is a valid pagetree. It must be a txexpr? where all elements are pagenode?, and each is unique within possible-pagetree (not counting the root node).

Examples:

> (pagetree? '(root index.html))

#t

> (pagetree? '(root duplicate.html duplicate.html))

#f

> (pagetree? '(root index.html "string.html"))

#f

> (define nested-ptree '(root 1.html 2.html (3.html 3a.html 3b.html)))
> (pagetree? nested-ptree)

#t

> (pagetree? `(root index.html ,nested-ptree (subsection.html more.html)))

#t

; Nesting a subtree twice creates duplication
> (pagetree? `(root index.html ,nested-ptree (subsection.html ,nested-ptree)))

#f

procedure

(validate-pagetree possible-pagetree)  pagetree?

  possible-pagetree : any/c
Like pagetree?, but raises a descriptive error if possible-pagetree is invalid, and otherwise returns possible-pagetree itself.

Examples:

> (validate-pagetree '(root (mama.html son.html daughter.html) uncle.html))

'(root (mama.html son.html daughter.html) uncle.html)

> (validate-pagetree `(root (,+ son.html daughter.html) uncle.html))

#f

> (validate-pagetree '(root (mama.html son.html son.html) mama.html))

validate-pagetree: items aren’t unique: (son.html mama.html)

procedure

(pagenode? possible-pagenode)  boolean?

  possible-pagenode : any/c
Test whether possible-pagenode is a valid pagenode. A pagenode can be any symbol? that is not whitespace/nbsp? Every leaf of a pagetree is a pagenode. In practice, your pagenodes will likely be names of output files.

Pagenodes are symbols (rather than strings) so that pagetrees will be valid tagged X-expressions, which is a more convenient format for validation & processing.

Examples:

; Three symbols, the third one annoying but valid
> (map pagenode? '(symbol index.html |   silly   |))

'(#t #t #t)

; A number, a string, a txexpr, and a whitespace symbol
> (map pagenode? '(9.999 "index.html" (p "Hello") |    |))

'(#f #f #f #f)

procedure

(pagenodeish? v)  boolean?

  v : any/c
Return #t if v can be converted with ->pagenode.

Example:

> (map pagenodeish? '(9.999 "index.html" |    |))

'(#t #t #f)

procedure

(->pagenode v)  pagenode?

  v : pagenodeish?
Convert v to a pagenode.

Examples:

> (map pagenodeish? '(symbol 9.999 "index.html" |  silly  |))

'(#t #t #t #t)

> (map ->pagenode '(symbol 9.999 "index.html" |  silly  |))

'(symbol |9.999| index.html |  silly  |)

8.4.1 Navigation

parameter

(current-pagetree)  pagetree?

(current-pagetree pagetree)  void?
  pagetree : pagetree?
A parameter that defines the default pagetree used by pagetree navigation functions (e.g., parent-pagenode, chidren, et al.) if another is not explicitly specified. Initialized to #f.

procedure

(parent p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Find the parent pagenode of p within pagetree. Return #f if there isn’t one.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (parent 'son.html)

'mama.html

> (parent "mama.html")

'root

> (parent (parent 'son.html))

'root

> (parent (parent (parent 'son.html)))

#f

procedure

(children p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Find the child pagenodes of p within pagetree. Return #f if there aren’t any.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (children 'mama.html)

'(son.html daughter.html)

> (children 'uncle.html)

#f

> (children 'root)

'(mama.html uncle.html)

> (map children (children 'root))

'((son.html daughter.html) #f)

procedure

(siblings p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Find the sibling pagenodes of p within pagetree. The list will include p itself. But the function will still return #f if pagetree is #f.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (siblings 'son.html)

'(son.html daughter.html)

> (siblings 'daughter.html)

'(son.html daughter.html)

> (siblings 'mama.html)

'(mama.html uncle.html)

procedure

(previous p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)

procedure

(previous* p [pagetree])  (or/c #f (listof pagenode?))

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Return the pagenode immediately before p. For previous*, return all the pagenodes before p, in sequence. In both cases, return #f if there aren’t any pagenodes. The root pagenode is ignored.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (previous 'daughter.html)

'son.html

> (previous 'son.html)

'mama.html

> (previous (previous 'daughter.html))

'mama.html

> (previous 'mama.html)

#f

> (previous* 'daughter.html)

'(mama.html son.html)

> (previous* 'uncle.html)

'(mama.html son.html daughter.html)

procedure

(next p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)

procedure

(next* p [pagetree])  (or/c #f (listof pagenode?))

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Return the pagenode immediately after p. For next*, return all the pagenodes after p, in sequence. In both cases, return #f if there aren’t any pagenodes. The root pagenode is ignored.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (next 'son.html)

'daughter.html

> (next 'daughter.html)

'uncle.html

> (next (next 'son.html))

'uncle.html

> (next 'uncle.html)

#f

> (next* 'mama.html)

'(son.html daughter.html uncle.html)

> (next* 'daughter.html)

'(uncle.html)

8.4.2 Utilities

procedure

(pagetree->list pagetree)  list?

  pagetree : pagetree?
Convert pagetree to a simple list. Equivalent to a pre-order depth-first traversal of pagetree.

procedure

(in-pagetree? pagenode [pagetree])  boolean?

  pagenode : pagenode?
  pagetree : pagetree? = (current-pagetree)
Report whether pagenode is in pagetree.

procedure

(path->pagenode p)  pagenode?

  p : pathish?
Convert path p to a pagenode — meaning, make it relative to current-project-root, run it through ->output-path, and convert it to a symbol. Does not tell you whether the resultant pagenode actually exists in the current pagetree (for that, use in-pagetree?).

 
\ No newline at end of file diff --git a/doc/World.html b/doc/World.html index 1740e2f..406f8b0 100644 --- a/doc/World.html +++ b/doc/World.html @@ -1,2 +1,12 @@ -8.9 World
Module reference
8.1 Cache
8.2 Decode
8.3 File
8.4 Pagetree
8.5 Render
8.6 Template
8.7 Tag
8.8 Top
8.9 World
On this page:
world:  default-port
world:  current-server-port
world:  main-pollen-export
world:  meta-pollen-export
world:  project-require
world:  check-project-requires-in-render?
world:  server-extras-dir
world:  current-server-extras-path
world:  preproc-source-ext
world:  markup-source-ext
world:  markdown-source-ext
world:  null-source-ext
world:  pagetree-source-ext
world:  template-source-ext
world:  scribble-source-ext
world:  decodable-extensions
world:  mode-auto
world:  mode-preproc
world:  mode-markup
world:  mode-markdown
world:  mode-pagetree
world:  default-pagetree
world:  pagetree-root-node
world:  command-marker
world:  default-template-prefix
world:  fallback-template
world:  template-meta-key
world:  newline
world:  linebreak-separator
world:  paragraph-separator
world:  dashboard-css
world:  paths-excluded-from-dashboard
6.0.1.6

8.9 World

 (require pollen/world) package: pollen

A set of global values and parameters that are used throughout the Pollen system. If you don’t like the defaults I’ve picked, change them.

All identifiers are exported with the prefix world:, and are so documented below.

value

world:default-port : integer? = 8080

A parameter that sets the HTTP port for the project server. Initialized to world:default-port, which defaults to 8080.

The two exports from a compiled Pollen source file.

value

world:project-require : string? = "project-require.rkt"

File implicitly required into every Pollen source file from its directory.

A parameter that determines whether the world:project-require file is checked for changes on every pass through render. (Can be faster to turn this off if you don’t need it.) Initialized to #t.

value

world:server-extras-dir : string? = "server-extras"

Name of directory where server support files live.

A parameter that reports the path to the directory of support files for the project server. Initialized to #f, but set to a proper value when the server runs.

File extensions for Pollen source files.

File extensions that are eligible for decoding.

value

world:mode-auto : symbol? = 'auto

value

world:mode-preproc : symbol? = 'pre

value

world:mode-markup : symbol? = 'markup

value

world:mode-markdown : symbol? = 'markdown

value

world:mode-pagetree : symbol? = 'ptree

Mode indicators for the Pollen reader and parser.

value

world:default-pagetree : string? = "index.ptree"

Pagetree that Pollen dashboard loads by default in each directory.

value

world:pagetree-root-node : symbol? = 'pagetree-root

Name of the root node in a decoded pagetree. It’s ignored by the code, so its only role is to clue you in that you’re looking at something that came out of the pagetree decoder.

value

world:command-marker : char? = #\◊

The magic character that indicates a Pollen command, function, or variable.

value

world:default-template-prefix : string? = "template"

Prefix of the default template.

value

world:fallback-template : string? = "fallback.html.pt"

Name of the fallback template (i.e., the template used to render a Pollen markup file when no other template can be found).

value

world:template-meta-key : symbol? = 'template

Meta key used to store a template name for that particular source file.

Default separators used in decoding.

value

world:dashboard-css : string? = "poldash.css"

CSS file used for the dashboard.

value

world:paths-excluded-from-dashboard : (listof path?)

 = (map string->path (list "poldash.css" "compiled"))
Paths not shown in the Pollen dashboard.

 
\ No newline at end of file +8.9 World
Module reference
8.1 Cache
8.2 Decode
8.3 File
8.4 Pagetree
8.5 Render
8.6 Template
8.7 Tag
8.8 Top
8.9 World
On this page:
world:  default-port
world:  current-server-port
world:  main-pollen-export
world:  meta-pollen-export
world:  project-require
world:  check-project-requires-in-render?
world:  server-extras-dir
world:  current-server-extras-path
world:  preproc-source-ext
world:  markup-source-ext
world:  markdown-source-ext
world:  null-source-ext
world:  pagetree-source-ext
world:  template-source-ext
world:  scribble-source-ext
world:  decodable-extensions
world:  mode-auto
world:  mode-preproc
world:  mode-markup
world:  mode-markdown
world:  mode-pagetree
world:  default-pagetree
world:  pagetree-root-node
world:  command-marker
world:  default-template-prefix
world:  fallback-template
world:  template-meta-key
world:  newline
world:  linebreak-separator
world:  paragraph-separator
world:  dashboard-css
world:  paths-excluded-from-dashboard
6.0.1.6

8.9 World

 (require pollen/world) package: pollen

A set of global values and parameters that are used throughout the Pollen system. If you don’t like the defaults I’ve picked, change them.

All identifiers are exported with the prefix world:, and are so documented below.

A parameter that sets the HTTP port for the project server. Initialized to world:default-port, which defaults to 8080.

The two exports from a compiled Pollen source file. Initialized to 'doc and 'metas, respectively.

File implicitly required into every Pollen source file from its directory. Initialized to "project-require.rkt".

A parameter that determines whether the world:project-require file is checked for changes on every pass through render. (Can be faster to turn this off if you don’t need it.) Initialized to #t.

Name of directory where server support files live. Initialized to "server-extras".

A parameter that reports the path to the directory of support files for the project server. Initialized to #f, but set to a proper value when the server runs.

File extensions for Pollen source files, initialized to the following values:

world:preproc-source-ext = pp +
world:markup-source-ext = pm +
world:markdown-source-ext = pmd +
world:null-source-ext = p +
world:pagetree-source-ext = ptree +
world:template-source-ext = pt +
world:scribble-source-ext = scrbl

File extensions that are eligible for decoding.

Mode indicators for the Pollen reader and parser. Initialized to the following values:

world:mode-auto = auto +
world:mode-preproc = pre +
world:mode-markup = markup +
world:mode-markdown = markdown +
world:mode-pagetree = ptree

Pagetree that Pollen dashboard loads by default in each directory. Initialized to "index.ptree".

Name of the root node in a decoded pagetree. It’s ignored by the code, so its only role is to clue you in that you’re looking at something that came out of the pagetree decoder. Initialized to 'pagetree-root.

The magic character that indicates a Pollen command, function, or variable. Initialized to #\◊.

Prefix of the default template. Initialized to "template".

Name of the fallback template (i.e., the template used to render a Pollen markup file when no other template can be found). Initialized to "fallback.html.pt".

Meta key used to store a template name for that particular source file. Initialized to 'template.

Default separators used in decoding. The first two are initialized to "\n"; the third to "\n\n".

CSS file used for the dashboard. Initialized to "poldash.css".

Paths not shown in the Pollen dashboard.

 
\ No newline at end of file diff --git a/doc/doc-site.css b/doc/doc-site.css new file mode 100644 index 0000000..e69de29 diff --git a/doc/doc-site.js b/doc/doc-site.js new file mode 100644 index 0000000..e69de29 diff --git a/doc/index.html b/doc/index.html index 549d9fb..74e1b95 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1,3 +1,3 @@ -Pollen: the book is a program
On this page:
Pollen:   the book is a program
6.0.1.6

Pollen: the book is a program

Matthew Butterick <mb@mbtype.com>

 #lang pollen package: pollen

Pollen is a publishing system that helps authors create beautiful and functional web-based books. Pollen includes tools for writing, designing, programming, testing, and publishing.

I used Pollen to create my book Butterick’s Practical Typography. Sure, go take a look. Is it better than the last digital book you encountered? Yes it is. Would you like your book to look like that? If so, keep reading.

At the core of Pollen is an argument: +Pollen: the book is a program
6.0.1.6

Pollen: the book is a program

Matthew Butterick <mb@mbtype.com>

 #lang pollen package: pollen

Pollen is a publishing system that helps authors create beautiful and functional web-based books. Pollen includes tools for writing, designing, programming, testing, and publishing.

I used Pollen to create my book Butterick’s Practical Typography. Sure, go take a look. Is it better than the last digital book you encountered? Yes it is. Would you like your book to look like that? If so, keep reading.

At the core of Pollen is an argument:
  • First, that digital books should be the best books we’ve ever had. So far, they’re not even close.

  • Second, that because digital books are software, an author shouldn’t think of a book as merely data. The book is a program.

  • Third, that the way we make digital books better than their predecessors is by exploiting this programmability.

That’s what Pollen is for.

Not that you need to be a programmer to use Pollen. On the contrary, the Pollen language is markup-based, so you can write & edit text naturally. But when you want to automate repetitive tasks, add cross-references, or pull in data from other sources, you can access a full programming language from within the text.

That language is Racket. I chose Racket because while the idea for Pollen had been with me for several years, it simply wasn’t possible to build it with other languages. So if it’s unfamiliar to you, don’t panic. It was unfamiliar to me. Once you see what you can do with Pollen & Racket, you may be persuaded. I was.

Or, if you can find a better digital-publishing tool, use that. But I’m never going back to the way I used to work.

    1 Installation

    2 Quick tour

      2.1 Creating a source file

      2.2 Running a source file

      2.3 Naming, saving, and rendering a source file

      2.4 The project server

      2.5 Intermission

      2.6 Pollen as a preprocessor

      2.7 Markdown mode

      2.8 Markup mode

      2.9 Templates

      2.10 PS for Scribble users

      2.11 The end of the beginning

    3 Backstory

      3.1 Web development and its discontents

      3.2 The better idea: a programming model

      3.3 “Now you have two problems”

      3.4 Rethinking the solution for digital books

      3.5 Enter Racket

      3.6 What is Pollen?

    4 System overview

      4.1 The book is a program

      4.2 One language, multiple dialects

      4.3 Development environment

      4.4 A special data structure for HTML

      4.5 Preprocessor source files

      4.6 Templated source files

      4.7 Utility source files

      4.8 Pagetrees

      4.9 Build & deploy

    5 Using raco pollen

      5.1 Making sure raco pollen works

      5.2 raco pollen

      5.3 raco pollen help

      5.4 raco pollen start

      5.5 raco pollen render

      5.6 raco pollen clone

    6 File formats

      6.1 Source formats

        6.1.1 Command syntax using ◊

        6.1.2 Any command is valid

        6.1.3 Standard exports

        6.1.4 Custom exports

        6.1.5 The project-require.rkt file

        6.1.6 Preprocessor (.pp extension)

        6.1.7 Markdown (.pmd extension)

        6.1.8 Markup (.pm extension)

        6.1.9 Pagetree (.ptree extension)

      6.2 Utility formats

        6.2.1 Scribble (.scrbl extension)

        6.2.2 Null (.p extension)

    7 ◊ command overview

      7.1 The golden rule

      7.2 The lozenge glyph (◊)

      7.3 The two command modes: text mode & Racket mode

        7.3.1 The command name

          7.3.1.1 Invoking tag functions

          7.3.1.2 Invoking other functions

          7.3.1.3 Inserting the value of a variable

          7.3.1.4 Inserting a comment

        7.3.2 The Racket arguments

        7.3.3 The text argument

      7.4 Further reading

    8 Module reference

      8.1 Cache

      8.2 Decode

        8.2.1 Block

        8.2.2 Typography

      8.3 File

      8.4 Pagetree

        8.4.1 Navigation

        8.4.2 Utilities

      8.5 Render

      8.6 Template

      8.7 Tag

      8.8 Top

      8.9 World

    9 Acknowledgments

    10 License & source code

    Index

 
\ No newline at end of file diff --git a/doc/manual-style.css b/doc/manual-style.css index d9e1783..a4bc28a 100644 --- a/doc/manual-style.css +++ b/doc/manual-style.css @@ -517,10 +517,13 @@ table.tocsublist { .toptoclink { font-weight: bold; - font-size: 110%; - margin-bottom: 0.5rem; - margin-top: 1.5rem; - display: inline-block; + font-size: 110% +} + +/* hack to add space around .toptoclink because markup is all td */ +.toptoclink:after { + content: " "; + font-size: 3rem; } .toclink { diff --git a/doc/pollen/Acknowledgments.html b/doc/pollen/Acknowledgments.html new file mode 100644 index 0000000..7f4907c --- /dev/null +++ b/doc/pollen/Acknowledgments.html @@ -0,0 +1,2 @@ + +9 Acknowledgments
6.0

9 Acknowledgments

One curious aspect of free software is that you can appropriate the benefits of other people’s work while making it look like your own. No such legerdemain here. Whatever effort I’ve put into Pollen is dwarfed by the epic accomplishments of the Racket development team. I thank all of them — especially Matthew Flatt, Jay McCarthy, and Matthias Felleisen — for making this tremendous tool available, for adding several features I suggested, and for patiently answering my dumb questions over the months.

Thank you to Greg Hendershott for his Markdown parser.

The best software tools do more than get the job done. They create an incentive to undertake jobs you wouldn’t have attempted before. Racket encouraged me to become a better programmer so I could create Pollen. Likewise, I hope that Pollen encourages you to make things you couldn’t before.

MB

 
\ No newline at end of file diff --git a/doc/pollen/Backstory.html b/doc/pollen/Backstory.html new file mode 100644 index 0000000..f59aae2 --- /dev/null +++ b/doc/pollen/Backstory.html @@ -0,0 +1,2 @@ + +3 Backstory
6.0

3 Backstory

I created Pollen to overcome limitations & frustrations I repeatedly encountered with existing web-publishing tools.

If you agree with my characterization of those problems, then you’ll probably like the solution that Pollen offers. If not, you probably won’t.

3.1 Web development and its discontents

I made my first web page in 1994, shortly after the web was invented. I opened my text editor (at the time, BBEdit), pecked out <html><body>Hello world</body></html>, then loaded it in Mosaic. So did a million other nerds.

If you weren’t around then, you didn’t miss much. Everything about the web was horrible: the web browsers, the computers running the browsers, the dial-up connections feeding the browsers, and of course HTML itself. At that point, the desktop-software experience was already slick and refined. By comparison, using the web felt like banging rocks together.

That’s no longer true. The web is now 20 years old. During that time, most parts of the web have improved dramatically — for instance, the connections are faster, the browsers are more sophisticated, the screens have more pixels.

But one part has not improved: the way we make web pages. Over the years, tools promising to simplify HTML development have come and mostly gone — from PageMill to Dreamweaver to WordPress to Jekyll. Meanwhile, true web jocks have remained loyal to the original HTML power tool: the humble text editor.

In one way, this makes sense. Web pages are mostly made of text-based data — HTML, CSS, JavaScript, and so on — and the simplest way to mainpulate this data is with a text editor. While HTML and CSS are not programming languages, they lend themselves to semantic and logical structure that’s most easily expressed by editing them as text. Furthermore, text-based editing makes debugging and performance improvements easier.

But text-based editing is also limited. Though the underlying description of a web page is notionally human-readable, it’s largely optimized to be readable by other software — namely, web browsers. HTML markup in particular is verbose and easily mistyped. And isn’t it fatally dull to manage all the boilerplate, like surrounding every paragraph with <p>...</p>? Yes, it is.

For these reasons, much of web development should lend itself to abstraction & automation. Abstraction means consolidating repetitve, complex patterns into simpler, parameterized forms. Automation means avoiding the manual drudgery of generating the output files. But in practice, tools that enable this abstraction & automation have been slow to arrive, and most have come hobbled with unacceptable deficiencies.

3.2 The better idea: a programming model

Parallel with my HTML education, I also goofed around with various programming languages — C, C++, Perl, Java, PHP, JavaScript, Python. Unlike HTML, programming languages excel at abstraction and automation. This seemed like the obvious direction for web development to go.

What distinguishes the text-editing model from the programming model? It’s a matter of direct vs. indirect manipulation of output. The text-editing model treats HTML as something to be written directly with a text editor. Whereas the programming model treats HTML — or whatever the output is — as the result of compiling a set of source files, which are written in a programming language. The costs of working indirectly via the programming language are offset by the benefits of abstraction & automation.

On the early web, the text-editing model was appealingly precise and quick. On small projects, it worked well enough. But as projects grew, the text-editing model was going to lose steam. I wasn’t the only one to notice. Shortly after those million nerds made their first web page by hand, many of them set about devising ways to apply a programming model to web development.

3.3 “Now you have two problems”

What followed was a steady stream of products, frameworks, tools, and content management systems that claimed to bring a programming model to web development. Some were better than others. But none of them displaced the text editor as the preferred tool of web developers.

Why not? All these tools promised a great leap forward in solving the web-development problem. In practice, they simply redistributed the pain. I needn’t bore you with enumerating the deficiencies of specific tools, because they’ve tended to fail in the same thematic ways:

  • No native data structure for HTML. Core to any programming model is data structures. Good data structures make processing easy; bad ones make it hard. Even though HTML has a well documented format, rarely has it been handled within a programming system with a native, intuitive data structure. Instead, it’s either been treated as a string (wrong), a tree (also wrong), or some magical parsed object. This has made working with HTML in programming environments needlessly difficult.

  • Mandatory separation of code, presentation, and content. This principle has often been held out as an ideal in web development. But it’s also counterintuitive, because an HTML page naturally contains all three. If you want to separate them, your tools should let you. But if you don’t, your tools shouldn’t make you.

  • Compromised template languages. Seems like every programming language has at least 10 templating systems for HTML, all of which require you to learn a new “template language” that offers the worst of both worlds: fewer features and different syntax than the underlying language.

  • Steep learning curves. Web programmers have often chided designers for not knowing how to code. But programming-based web-development tools have often had a high initial learning curve that requires you to throw out your existing workflow. Programmers built these tools — no surprise that programmers have been more comfortable with them.

I’ve tried a lot of these tools over the years. Some I liked. Some I didn’t. Invariably, however, whenever I could still make do with hand-editing an HTML project, I would. After trying to cajole the web framework du jour into doing my bidding, it was relaxing to trade off some efficiency for control.

3.4 Rethinking the solution for digital books

In 2008, I launched a website called Typography for Lawyers. Initially, I’d conceived of it as a book. Then I thought “no one’s going to publish that.” So it became a website, that I aimed to make as book-like as possible. But hand-editing wasn’t going to be enough.

So I used WordPress. The major chore became scraping out all the crap that typically lives in blog templates. Largely because of this, people liked the site, because it was simpler & cleaner than the usual WordPress website.

Eventually, a publisher offered to release it as a paperback. Later came the inevitable request to make it into a Kindle book. As a fan of typography, I hate the Kindle. The layout controls are coarse, and so is the reading experience. But I didn’t run and hide. Basically a Kindle book is a little website made with 1995-era HTML. So I coded up some tools in Perl to convert my book to Kindle format while preserving the formatting and images as well as possible.

At that point, I noticed I had converted Typography for Lawyers into web format twice, using two different sets of tools. Before someone asked me to do it a third time, I started thinking about how I might create source code for the book that allowed me to render it into different formats.

This was the beginning of the Pollen project.

I wrote the initial version of Pollen in Python. I devised a simplified markup-notation language for the source files. This language was compiled into XML-ish data structures using ply (Python lex/yacc). These structures were parsed into trees using LXML. The trees were combined with templates made in Chameleon. These templates were rendered and previewed with the Bottle web server.

Did it work? Sort of. Source code went in; web pages came out. But it was also complicated and fragile. Moreover, though the automation was there, there wasn’t yet enough abstraction at the source layer. I started thinking about how I could add a source preprocessor.

3.5 Enter Racket

I had come across Racket while researching languages suitable for HTML/XML processing. I had unexpectedly learned about the secret kinship of XML and Lisp: though XML is not a programming language, it uses a variant of Lisp syntax. Thus Lisp languages are particularly adept at handling XMLish structures. That was interesting.

After comparing some of the Lisp & Scheme variants, Racket stood out because it had a text-based dialect called Scribble. Scribble could be used to embed code within textual content. That was interesting too. Among other things, this meant Scribble could be used as a general-purpose preprocessor. So I thought I’d see if I could add it to Pollen.

It worked. So well, in fact, that I started thinking about whether I could reimplement other parts of Pollen in Racket. Then I started thinking about reimplementing all of it in Racket.

So I did. And here we are.

3.6 What is Pollen?

Pollen is a publishing system built on top of Scribble and Racket. So far I’ve optimized Pollen for digital books, because that’s mainly what I use it for. But it can be used for small projects too.

As a publishing system, Pollen includes:

  • A programming language. The Pollen language is a variant of Scribble, with specific “dialects” tailored to different kinds of source files. You don’t need to use the programming features to do useful work, but they’re available when you need them.

  • A set of tools & libraries. Pollen targets HTML output. So it includes a variety of tools that cure common HTML annoyances, including a CSS preprocessor.

  • A development environment. Pollen works with the DrRacket IDE. It also includes a project web server so you can dynamically preview and revise your publication.

Pollen addresses the deficiencies I experienced with other tools:

  • Yes, we have a native data structure for HTML. Racket represents HTML structures as X-expressions, which are a variant of the standard Racket data structure, called S-expressions. In other words, not only is there a native representation for HTML, everything in the language is represented this way.

  • Flexible blending of code, presentation, and content. Pollen is a text-based language. So a Pollen source file might have no code at all. But as a dialect of Scribble & Racket, if you want to mix code with content, you can.

  • No template language. It’s not necessary, because you can use the whole Racket language, and all the usual Racket syntax, in every Pollen file.

  • Shallow learning curve. You don’t need to do a lot of setup and configuration to start doing useful work with Pollen. Programmers and non-programmers can easily collaborate. Yes, I concede that if you plan to get serious, you’ll need to learn some Racket. I don’t think you’ll regret it.

 
\ No newline at end of file diff --git a/doc/pollen/Cache.html b/doc/pollen/Cache.html new file mode 100644 index 0000000..1d9ac3f --- /dev/null +++ b/doc/pollen/Cache.html @@ -0,0 +1,2 @@ + +8.1 Cache
6.0

8.1 Cache

 (require pollen/cache) package: pollen

The slowest part of a render is parsing and decoding the source file. Often, previewing a single source file necessarily means decoding others (for instance templates, or other source files that are linked into the main source file). But usually, only one source file is changing at a time. Therefore, Pollen stores copies of the exports of source files — namely, whatever is stored in doc and metas — in the cache so they can be reused.

parameter

(current-cache)  hash?

(current-cache hash)  void?
  hash : hash?
A parameter that refers to the current cache. It is initialized with make-cache.

The cache is a hash table that uses the complete path of a source file as its keys. The value associated with each of these keys is a subcache — another hash table with keys 'doc, 'metas (for storing the exports of the source file) and 'mod-time (for storing the modification time, provided by file-or-directory-modify-seconds).

procedure

(cached-require source-path key)  (or/c txexpr? hash? integer?)

  source-path : pathish?
  key : (or/c 'doc 'metas 'mod-time)
Similar to (dynamic-require source-path key), except that it first tries to retrieve the requested value out of current-cache. If it’s not there, or out of date, dynamic-require is used to update the value.

The only keys supported are 'doc, 'metas, and 'mod-time.

If you want the speed benefit of the cache, you should always use cached-require to get data from Pollen source files. That doesn’t mean you can’t still use functions like require, local-require, and dynamic-require. They’ll just be slower.

procedure

(make-cache)  hash?

Initializes current-cache.

procedure

(reset-cache)  void?

Clears current-cache. When only the nuclear option will do.

procedure

(cache-ref source-path)  hash?

  source-path : pathish?
Returns the subcache associated with the key source-path, which will itself be a hash table. See current-cache.

 
\ No newline at end of file diff --git a/doc/pollen/Decode.html b/doc/pollen/Decode.html new file mode 100644 index 0000000..efd6bc0 --- /dev/null +++ b/doc/pollen/Decode.html @@ -0,0 +1,2 @@ + +8.2 Decode
6.0

8.2 Decode

 (require pollen/decode) package: pollen

The doc export of a Pollen markup file is a simple X-expression. Decoding refers to any post-processing of this X-expression. The pollen/decode module provides tools for creating decoders.

The decode step can happen separately from the compilation of the file. But you can also attach a decoder to the markup file’s root node, so the decoding happens automatically when the markup is compiled, and thus automatically incorporated into doc. (Following this approach, you could also attach multiple decoders to different tags within doc.)

You can, of course, embed function calls within Pollen markup. But since markup is optimized for authors, decoding is useful for operations that can or should be moved out of the authoring layer.

One example is presentation and layout. For instance, detect-paragraphs is a decoder function that lets authors mark paragraphs in their source simply by using two carriage returns.

Another example is conversion of output into a particular data format. Most Pollen functions are optimized for HTML output, but one could write a decoder that targets another format.

procedure

(decode tagged-xexpr    
  [#:txexpr-tag-proc txexpr-tag-proc    
  #:txexpr-attrs-proc txexpr-attrs-proc    
  #:txexpr-elements-proc txexpr-elements-proc    
  #:block-txexpr-proc block-txexpr-proc    
  #:inline-txexpr-proc inline-txexpr-proc    
  #:string-proc string-proc    
  #:symbol-proc symbol-proc    
  #:valid-char-proc valid-char-proc    
  #:cdata-proc cdata-proc    
  #:exclude-tags tags-to-exclude])  txexpr?
  tagged-xexpr : txexpr?
  txexpr-tag-proc : (txexpr-tag? . -> . txexpr-tag?)
   = (λ(tag) tag)
  txexpr-attrs-proc : (txexpr-attrs? . -> . txexpr-attrs?)
   = (λ(attrs) attrs)
  txexpr-elements-proc : (txexpr-elements? . -> . txexpr-elements?)
   = (λ(elements) elements)
  block-txexpr-proc : (block-txexpr? . -> . xexpr?) = (λ(tx) tx)
  inline-txexpr-proc : (txexpr? . -> . xexpr?) = (λ(tx) tx)
  string-proc : (string? . -> . xexpr?) = (λ(str) str)
  symbol-proc : (symbol? . -> . xexpr?) = (λ(sym) sym)
  valid-char-proc : (valid-char? . -> . xexpr?) = (λ(vc) vc)
  cdata-proc : (cdata? . -> . xexpr?) = (λ(cdata) cdata)
  tags-to-exclude : (listof symbol?) = null
Recursively process a tagged-xexpr, usually the one exported from a Pollen source file as doc.

This function doesn’t do much on its own. Rather, it provides the hooks upon which harder-working functions can be hung.

Recall from [future link: Pollen mechanics] that any tag can have a function attached to it. By default, the tagged-xexpr from a source file is tagged with root. So the typical way to use decode is to attach your decoding functions to it, and then define root to invoke your decode function. Then it will be automatically applied to every doc during compile.

For instance, here’s how decode is attached to root in Butterick’s Practical Typography. There’s not much to it —

[update with actual code]

This illustrates another important point: even though decode presents an imposing list of arguments, you’re unlikely to use all of them at once. These represent possibilities, not requirements. For instance, let’s see what happens when decode is invoked without any of its optional arguments.

Examples:

> (define tx '(root "I wonder" (em "why") "this works."))
> (decode tx)

'(root "I wonder" (em "why") "this works.")

Right — nothing. That’s because the default value for the decoding arguments is the identity function, (λ (x) x). So all the input gets passed through intact unless another action is specified.

The *-proc arguments of decode take procedures that are applied to specific categories of elements within txexpr.

The txexpr-tag-proc argument is a procedure that handles X-expression tags.

Examples:

> (define tx '(p "I'm from a strange" (strong "namespace")))
; Tags are symbols, so a tag-proc should return a symbol
> (decode tx #:txexpr-tag-proc (λ(t) (string->symbol (format "ns:~a" t))))

'(ns:p "I'm from a strange" (ns:strong "namespace"))

The txexpr-attrs-proc argument is a procedure that handles lists of X-expression attributes. (The txexpr module, included at no extra charge with Pollen, includes useful helper functions for dealing with these attribute lists.)

Examples:

> (define tx '(p [[id "first"]] "If I only had a brain."))
; Attrs is a list, so cons is OK for simple cases
> (decode tx #:txexpr-attrs-proc (λ(attrs) (cons '[class "PhD"] attrs)))

'(p ((class "PhD") (id "first")) "If I only had a brain.")

Note that txexpr-attrs-proc will change the attributes of every tagged X-expression, even those that don’t have attributes. This is useful, because sometimes you want to add attributes where none existed before. But be careful, because the behavior may make your processing function overinclusive.

Examples:

> (define tx '(div (p [[id "first"]] "If I only had a brain.")
  (p "Me too.")))
; This will insert the new attribute everywhere
> (decode tx #:txexpr-attrs-proc (λ(attrs) (cons '[class "PhD"] attrs)))

'(div

  ((class "PhD"))

  (p ((class "PhD") (id "first")) "If I only had a brain.")

  (p ((class "PhD")) "Me too."))

; This will add the new attribute only to non-null attribute lists
> (decode tx #:txexpr-attrs-proc
  (λ(attrs) (if (null? attrs) attrs (cons '[class "PhD"] attrs))))

'(div (p ((class "PhD") (id "first")) "If I only had a brain.") (p "Me too."))

The txexpr-elements-proc argument is a procedure that operates on the list of elements that represents the content of each tagged X-expression. Note that each element of an X-expression is subject to two passes through the decoder: once now, as a member of the list of elements, and also later, through its type-specific decoder (i.e., string-proc, symbol-proc, and so on).

Examples:

> (define tx '(div "Double" "\n" "toil" amp "trouble"))
; Every element gets doubled ...
> (decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) `(,e ,e)) es)))

'(div "Double" "Double" "\n" "\n" "toil" "toil" amp amp "trouble" "trouble")

; ... but only strings get capitalized
> (decode tx #:txexpr-elements-proc (λ(es) (append-map (λ(e) `(,e ,e)) es))
  #:string-proc (λ(s) (string-upcase s)))

'(div "DOUBLE" "DOUBLE" "\n" "\n" "TOIL" "TOIL" amp amp "TROUBLE" "TROUBLE")

So why do you need txexpr-elements-proc? Because some types of element decoding depend on context, thus it’s necessary to handle the elements as a group. For instance, the doubling function above, though useless, requires handling the element list as a whole, because elements are being added.

A more useful example: paragraph detection. The behavior is not merely a map across each element:

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
; Context matters. Trailing whitespace is ignored ...
> (paras '(body "The first paragraph." "\n\n"))

'(body "The first paragraph.")

; ... but whitespace between strings is converted to a break.
> (paras '(body "The first paragraph." "\n\n" "And another."))

'(body (p "The first paragraph.") (p "And another."))

; A combination of both types
> (paras '(body "The first paragraph." "\n\n" "And another." "\n\n"))

'(body (p "The first paragraph.") (p "And another."))

The block-txexpr-proc argument and the inline-txexpr-proc arguments are procedures that operate on tagged X-expressions. If the X-expression meets the block-txexpr? test, it is processed by block-txexpr-proc. Otherwise, it is processed by inline-txexpr-proc. Thus every tagged X-expression will be handled by one or the other. Of course, if you want block and inline elements to be handled the same way, you can set block-txexpr-proc and inline-txexpr-proc to be the same procedure.

Examples:

> (define tx '(div "Please" (em "mind the gap") (h1 "Tuesdays only")))
> (define add-ns (λ(tx) (make-txexpr
      (string->symbol (format "ns:~a" (get-tag tx)))
      (get-attrs tx)
      (get-elements tx))))
; div and h1 are block elements, so this will only affect them
> (decode tx #:block-txexpr-proc add-ns)

'(ns:div "Please" (em "mind the gap") (ns:h1 "Tuesdays only"))

; em is an inline element, so this will only affect it
> (decode tx #:inline-txexpr-proc add-ns)

'(div "Please" (ns:em "mind the gap") (h1 "Tuesdays only"))

; this will affect all elements
> (decode tx #:block-txexpr-proc add-ns #:inline-txexpr-proc add-ns)

'(ns:div "Please" (ns:em "mind the gap") (ns:h1 "Tuesdays only"))

The string-proc, symbol-proc, valid-char-proc, and cdata-proc arguments are procedures that operate on X-expressions that are strings, symbols, valid-chars, and CDATA, respectively. Deliberately, the output contracts for these procedures accept any kind of X-expression (meaning, the procedure can change the X-expression type).

Examples:

; A div with string, entity, character, and cdata elements
> (define tx `(div "Moe" amp 62 ,(cdata #f #f "3 > 2;")))
> (define rulify (λ(x) '(hr)))
; The rulify function is selectively applied to each
> (print (decode tx #:string-proc rulify))

'(div (hr) amp 62 #(struct:cdata #f #f "3 > 2;"))

> (print (decode tx #:symbol-proc rulify))

'(div "Moe" (hr) 62 #(struct:cdata #f #f "3 > 2;"))

> (print (decode tx #:valid-char-proc rulify))

'(div "Moe" amp (hr) #(struct:cdata #f #f "3 > 2;"))

> (print (decode tx #:cdata-proc rulify))

'(div "Moe" amp 62 (hr))

Finally, the tags-to-exclude argument is a list of tags that will be exempted from decoding. Though you could get the same result by testing the input within the individual decoding functions, that’s tedious and potentially slower.

Examples:

> (define tx '(p "I really think" (em "italics") "should be lowercase."))
> (decode tx #:string-proc (λ(s) (string-upcase s)))

'(p "I REALLY THINK" (em "ITALICS") "SHOULD BE LOWERCASE.")

> (decode tx #:string-proc (λ(s) (string-upcase s)) #:exclude-tags '(em))

'(p "I REALLY THINK" (em "italics") "SHOULD BE LOWERCASE.")

The tags-to-exclude argument is useful if you’re decoding source that’s destined to become HTML. According to the HTML spec, material within a <style> or <script> block needs to be preserved literally. In this example, if the CSS and JavaScript blocks are capitalized, they won’t work. So exclude '(style script), and problem solved.

Examples:

> (define tx '(body (h1 [[class "Red"]] "Let's visit Planet Telex.")
  (style [[type "text/css"]] ".Red {color: green;}")
  (script [[type "text/javascript"]] "var area = h * w;")))
> (decode tx #:string-proc (λ(s) (string-upcase s)))

'(body

  (h1 ((class "Red")) "LET'S VISIT PLANET TELEX.")

  (style ((type "text/css")) ".RED {COLOR: GREEN;}")

  (script ((type "text/javascript")) "VAR AREA = H * W;"))

> (decode tx #:string-proc (λ(s) (string-upcase s))
  #:exclude-tags '(style script))

'(body

  (h1 ((class "Red")) "LET'S VISIT PLANET TELEX.")

  (style ((type "text/css")) ".Red {color: green;}")

  (script ((type "text/javascript")) "var area = h * w;"))

8.2.1 Block

Because it’s convenient, Pollen categorizes tagged X-expressions into two categories: block and inline. Why is it convenient? When using decode, you often want to treat the two categories differently. Not that you have to. But this is how you can.

parameter

(project-block-tags)  (listof txexpr-tag?)

(project-block-tags block-tags)  void?
  block-tags : (listof txexpr-tag?)
A parameter that defines the set of tags that decode will treat as blocks. This parameter is initialized with the HTML block tags, namely:

(address article aside audio blockquote body canvas dd div dl fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hgroup noscript ol output p pre section table tfoot ul video)

procedure

(register-block-tag tag)  void?

  tag : txexpr-tag?
Adds a tag to project-block-tags so that block-txexpr? will report it as a block, and decode will process it with block-txexpr-proc rather than inline-txexpr-proc.

Pollen tries to do the right thing without being told. But this is the rare case where you have to be explicit. If you introduce a tag into your markup that you want treated as a block, you must use this function to identify it, or you will get spooky behavior later on.

For instance, detect-paragraphs knows that block elements in the markup shouldn’t be wrapped in a p tag. So if you introduce a new block element called bloq without registering it as a block, misbehavior will follow:

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
> (paras '(body "I want to be a paragraph." "\n\n" (bloq "But not me.")))

'(body (p "I want to be a paragraph.") (p (bloq "But not me.")))

; Wrong: bloq should not be wrapped

But once you register bloq as a block, order is restored:

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
> (register-block-tag 'bloq)
> (paras '(body "I want to be a paragraph." "\n\n" (bloq "But not me.")))

'(body (p "I want to be a paragraph.") (bloq "But not me."))

; Right: bloq is treated as a block

If you find the idea of registering block tags unbearable, good news. The project-block-tags include the standard HTML block tags by default. So if you just want to use things like div and p and h1–h6, you’ll get the right behavior for free.

Examples:

> (define (paras tx) (decode tx #:txexpr-elements-proc detect-paragraphs))
> (paras '(body "I want to be a paragraph." "\n\n" (div "But not me.")))

'(body (p "I want to be a paragraph.") (div "But not me."))

procedure

(block-txexpr? v)  boolean?

  v : any/c
Predicate that tests whether v is a tagged X-expression, and if so, whether the tag is among the project-block-tags. If not, it is treated as inline. To adjust how this test works, use register-block-tag.

8.2.2 Typography

An assortment of typography & layout functions, designed to be used with decode. These aren’t hard to write. So if you like these, use them. If not, make your own.

procedure

(whitespace? v)  boolean?

  v : any/c
A predicate that returns #t for any stringlike v that’s entirely whitespace, but also the empty string, as well as lists and vectors that are made only of whitespace? members. Following the regexp-match convention, whitespace? does not return #t for a nonbreaking space. If you prefer that behavior, use whitespace/nbsp?.

Examples:

> (whitespace? "\n\n   ")

#t

> (whitespace? (string->symbol "\n\n   "))

#t

> (whitespace? "")

#t

> (whitespace? '("" "  " "\n\n\n" " \n"))

#t

> (define nonbreaking-space (format "~a" #\u00A0))
> (whitespace? nonbreaking-space)

#f

procedure

(whitespace/nbsp? v)  boolean?

  v : any/c
Like whitespace?, but also returns #t for nonbreaking spaces.

Examples:

> (whitespace/nbsp? "\n\n   ")

#t

> (whitespace/nbsp? (string->symbol "\n\n   "))

#t

> (whitespace/nbsp? "")

#t

> (whitespace/nbsp? '("" "  " "\n\n\n" " \n"))

#t

> (define nonbreaking-space (format "~a" #\u00A0))
> (whitespace/nbsp? nonbreaking-space)

#t

procedure

(smart-quotes str)  string?

  str : string?
Convert straight quotes in str to curly according to American English conventions.

Examples:

> (define tricky-string
  "\"Why,\" she could've asked, \"are we in O‘ahu watching 'Mame'?\"")
> (display tricky-string)

"Why," she could've asked, "are we in O‘ahu watching 'Mame'?"

> (display (smart-quotes tricky-string))

“Why,” she could’ve asked, “are we in O‘ahu watching ‘Mame’?”

procedure

(smart-dashes str)  string?

  str : string?
In str, convert three hyphens to an em dash, and two hyphens to an en dash, and remove surrounding spaces.

Examples:

> (define tricky-string "I had a few --- OK, like 6--8 --- thin mints.")
> (display tricky-string)

I had a few --- OK, like 6--8 --- thin mints.

> (display (smart-dashes tricky-string))

I had a few—OK, like 6–8—thin mints.

; Monospaced font not great for showing dashes, but you get the idea

procedure

(detect-linebreaks tagged-xexpr-elements 
  [#:separator linebreak-sep 
  #:insert linebreak]) 
  txexpr-elements?
  tagged-xexpr-elements : txexpr-elements?
  linebreak-sep : string? = world:linebreak-separator
  linebreak : xexpr? = '(br)
Within tagged-xexpr-elements, convert occurrences of linebreak-sep ("\n" by default) to linebreak, but only if linebreak-sep does not occur between blocks (see block-txexpr?). Why? Because block-level elements automatically display on a new line, so adding linebreak would be superfluous. In that case, linebreak-sep just disappears.

Examples:

> (detect-linebreaks '(div "Two items:" "\n" (em "Eggs") "\n" (em "Bacon")))

'(div "Two items:" (br) (em "Eggs") (br) (em "Bacon"))

> (detect-linebreaks '(div "Two items:" "\n" (div "Eggs") "\n" (div "Bacon")))

'(div "Two items:" (div "Eggs") (div "Bacon"))

procedure

(detect-paragraphs elements 
  [#:separator paragraph-sep 
  #:tag paragraph-tag 
  #:linebreak-proc linebreak-proc]) 
  txexpr-elements?
  elements : txexpr-elements?
  paragraph-sep : string? = world:paragraph-separator
  paragraph-tag : symbol? = 'p
  linebreak-proc : (txexpr-elements? . -> . txexpr-elements?)
   = detect-linebreaks
Find paragraphs within elements, as denoted by paragraph-sep, and wrap them with paragraph-tag, unless the element is already a block-txexpr? (because in that case, the wrapping is superfluous). Thus, as a consequence, if paragraph-sep occurs between two blocks, it’s ignored.

The paragraph-tag argument sets the tag used to wrap paragraphs.

The linebreak-proc argument allows you to use a different linebreaking procedure other than the usual detect-linebreaks.

Examples:

> (detect-paragraphs '("First para" "\n\n" "Second para"))

'((p "First para") (p "Second para"))

> (detect-paragraphs '("First para" "\n\n" "Second para" "\n" "Second line"))

'((p "First para") (p "Second para" (br) "Second line"))

> (detect-paragraphs '("First para" "\n\n" (div "Second block")))

'((p "First para") (div "Second block"))

> (detect-paragraphs '((div "First block") "\n\n" (div "Second block")))

'((div "First block") (div "Second block"))

> (detect-paragraphs '("First para" "\n\n" "Second para") #:tag 'ns:p)

'((ns:p "First para") (ns:p "Second para"))

> (detect-paragraphs '("First para" "\n\n" "Second para" "\n" "Second line")
  #:linebreak-proc (λ(x) (detect-linebreaks x #:insert '(newline))))

'((p "First para") (p "Second para" (newline) "Second line"))

 
\ No newline at end of file diff --git a/doc/pollen/File.html b/doc/pollen/File.html new file mode 100644 index 0000000..7a66fcf --- /dev/null +++ b/doc/pollen/File.html @@ -0,0 +1,2 @@ + +8.3 File
6.0

8.3 File

 (require pollen/file) package: pollen

A utility module that provides functions for working with Pollen source and output files. The tests rely on file extensions specified in pollen/world.

Pollen handles six kinds of source files:

Preprocessor, with file extension .pp.

Markup, with file extension .pm.

Template, with file extension .pt.

Null, with file extension .p.

Scribble, with file extension .scrbl.

For each kind of Pollen source file, the corresponding output file is generated by removing the extension from the name of the source file. So the preprocessor source file default.css.pp would become default.css. Scribble files work differently — the corresponding output file is the source file but with an html extension rather than scrbl. So pollen.scrbl would become pollen.html.

procedure

(preproc-source? v)  boolean?

  v : any/c

procedure

(markup-source? v)  boolean?

  v : any/c

procedure

(template-source? v)  boolean?

  v : any/c

procedure

(null-source? v)  boolean?

  v : any/c

procedure

(scribble-source? v)  boolean?

  v : any/c

procedure

(pagetree-source? v)  boolean?

  v : any/c
Test whether v is a path representing a source file of the specified type, based on file extension.

Examples:

> (preproc-source? "main.css.pp")

#t

> (markup-source? "default.html.pm")

#t

> (template-source? "main.html.pt")

#t

> (null-source? "index.html.p")

#t

> (scribble-source? "file.scrbl")

#t

> (pagetree-source? "index.ptree")

#t

procedure

(has-preproc-source? v)  boolean?

  v : any/c

procedure

(has-markup-source? v)  boolean?

  v : any/c

procedure

(has-template-source? v)  boolean?

  v : any/c

procedure

(has-null-source? v)  boolean?

  v : any/c

procedure

(has-scribble-source? v)  boolean?

  v : any/c
Test whether v is the output path for an existing source file of the specified type.

procedure

(has/is-preproc-source? v)  boolean?

  v : any/c

procedure

(has/is-markup-source? v)  boolean?

  v : any/c

procedure

(has/is-template-source? v)  boolean?

  v : any/c

procedure

(has/is-null-source? v)  boolean?

  v : any/c

procedure

(has/is-scribble-source? v)  boolean?

  v : any/c
Test whether v is a path representing a source file of the specified type, or is the output path for an existing source file of the specified type. In other words, has/is-preproc-source? is equivalent to (or (preproc-source? v) (has-preproc-source? v)).

procedure

(->preproc-source-path p)  path?

  p : pathish?

procedure

(->markup-source-path p)  path?

  p : pathish?

procedure

(->template-source-path p)  path?

  p : pathish?

procedure

(->null-source-path p)  path?

  p : pathish?

procedure

(->scribble-source-path p)  path?

  p : pathish?
Convert an output path p into the source path of the specified type that would produce this output path. This function simply generates a path for a file — it does not ask whether the file exists.

Examples:

> (define name "default.html")
> (->preproc-source-path name)

#<path:default.html.pp>

> (->markup-source-path name)

#<path:default.html.pm>

> (->template-source-path name)

#<path:default.html.pt>

> (->scribble-source-path name)

#<path:default.scrbl>

> (->null-source-path name)

#<path:default.html.p>

procedure

(->output-path p)  path?

  p : pathish?
Convert a source path p into its corresponding output path. This function simply generates a path for a file — it does not ask whether the file exists.

Examples:

> (->output-path "main.css.pp")

#<path:main.css>

> (->output-path "default.html.pm")

#<path:default.html>

> (->output-path "index.html.p")

#<path:index.html>

> (->output-path "file.scrbl")

#<path:file.html>

 
\ No newline at end of file diff --git a/doc/pollen/File_formats.html b/doc/pollen/File_formats.html new file mode 100644 index 0000000..edd6c4c --- /dev/null +++ b/doc/pollen/File_formats.html @@ -0,0 +1,2 @@ + +6 File formats
6.0

6 File formats

6.1 Source formats

 #lang pollen/pre package: pollen
 #lang pollen/markdown
 #lang pollen/markup
 #lang pollen/ptree

The Pollen language is divided into variants, or dialects, that are tailored to suit each of the core source formats.

These dialects can be invoked one of two ways: either by invoking a specific dialect in the first line of the file (also known as the #lang line), or by using the generic #lang pollen as the first line, and then the correct dialect will be automatically selected based on the source file extension.

If the #lang line specifies a dialect different from the one specified by the file extension, the #lang line will take precedence.

For ease of use, the behavior of the Pollen language departs from the standard Racket language in several ways. The differences are noted below.

6.1.1 Command syntax using ◊

Commands must start with the special lozenge character . Other material is interpreted as plain text. See ◊ command overview for more.

How is this different from Racket? In Racket, everything is a command, and plain text must be quoted.

6.1.2 Any command is valid

There are no undefined commands in Pollen. If a command has not already been defined, it’s treated as a tag function. See ◊ command overview for more.

How is this different from Racket? In Racket, if you try to treat an identifier as a function before defining it with define, you’ll get an error.

6.1.3 Standard exports

By default, every Pollen source file exports two symbols, which you can access by using the source file with require:

'doc contains the output of the file. The type of output depends on the source format (documented below).

'metas is a hash of key–value pairs with extra information that is extracted from the source. These 'metas will always contain the key 'here-path, which returns a string representation of the full path to the source file. Beyond that, the only 'metas are the ones that are specified within the source file (see the source formats below for more detail on how to specify metas).

How is this different from Racket? In Racket, you must explicitly define and then provide any values you want to export.

6.1.4 Custom exports

Any value or function that is defined within the source file using define is automatically exported.

How is this different from Racket? In Racket, you must explicitly provide any values you want to export. Unlike Racket, every Pollen source file impliedly uses (provide (all-defined-out)).

6.1.5 The project-require.rkt file

If a file called project-require.rkt exists in the same directory with a source file, it’s automatically imported when the source file is compiled.

How is this different from Racket? In Racket, you must explicitly import files using require.

6.1.6 Preprocessor (.pp extension)

Invoke the preprocessor dialect by using #lang pollen/pre as the first line of your source file, or by using #lang pollen with a file extension of .pp. These forms are equivalent:

"sample.css.pp"

#lang pollen
...source...

"sample.css"

#lang pollen/pre
...source...

When no dialect is explicitly specified by either the #lang line or the file extension, Pollen will default to using the preprocessor dialect. For instance, this file will be treated as preprocessor source:

"test.yyz"

#lang pollen
...source...

Of course, you’re better off specifying the preprocessor dialect explicitly rather than relying on this default behavior.

The output of the preprocessor dialect, provided by 'doc, is plain text.

6.1.7 Markdown (.pmd extension)

Invoke the Markdown dialect by using #lang pollen/markdown as the first line of your source file, or by using #lang pollen with a file extension of .pmd. These forms are equivalent:

"sample.txt.pmd"

#lang pollen
...source...

"sample.txt"

#lang pollen/markdown
...source...

The output of the Markdown dialect, provided by 'doc, is a tagged X-expression.

6.1.8 Markup (.pm extension)

Invoke the Pollen markup dialect by using #lang pollen/markup as the first line of your source file, or by using #lang pollen with a file extension of .pm. These forms are equivalent:

"about.html.pm"

#lang pollen
...source...

"about.html"

#lang pollen/markup
...source...

The output of the Pollen markup dialect, provided by 'doc, is a tagged X-expression.

6.1.9 Pagetree (.ptree extension)

Invoke the pagetree dialect by using #lang pollen/ptree as the first line of your source file, or by using #lang pollen with a file extension of .ptree. These forms are equivalent:

"main.ptree"

#lang pollen
...source...

"main.rkt"

#lang pollen/ptree
...source...

The output of the pagetree dialect, provided by 'doc, is a pagetree? that is checked for correctness using validate-pagetree.

6.2 Utility formats

These aren’t source formats because they don’t contain a #lang pollen line. But for convenience, they get special handling by the Pollen project server.

6.2.1 Scribble (.scrbl extension)

Scribble files are recognized by the project server and can be compiled and previewed in single-page mode.

6.2.2 Null (.p extension)

Files with the null extension are simply rendered as a copy of the file without the extension, so index.html.p becomes index.html.

This can be useful you’re managing your project with git. Most likely you’ll want to ignore *.html and other file types that are frequently regenerated by the project server. But if you have isolated static files — for instance, a index.html that doesn’t have source associated with it — they’ll be ignored too. You can cure this problem by appending the null extension to these static files, so they’ll be tracked in your source system without actually being source files.

 
\ No newline at end of file diff --git a/doc/pollen/Installation.html b/doc/pollen/Installation.html new file mode 100644 index 0000000..a1cb7ac --- /dev/null +++ b/doc/pollen/Installation.html @@ -0,0 +1,4 @@ + +1 Installation
6.0

1 Installation

Install Racket, which includes DrRacket.

Install Pollen from the command line: +

raco pkg install pollen

After that, you can update the package from the command line: +

raco pkg update pollen

 
\ No newline at end of file diff --git a/doc/pollen/License___source_code.html b/doc/pollen/License___source_code.html new file mode 100644 index 0000000..59169a4 --- /dev/null +++ b/doc/pollen/License___source_code.html @@ -0,0 +1,2 @@ + +10 License & source code
6.0

10 License & source code

This module is licensed under the LGPL.

Source repository at http://github.com/mbutterick/pollen. Suggestions & corrections welcome.

 
\ No newline at end of file diff --git a/doc/pollen/Module_reference.html b/doc/pollen/Module_reference.html new file mode 100644 index 0000000..2bcc68d --- /dev/null +++ b/doc/pollen/Module_reference.html @@ -0,0 +1,2 @@ + +8 Module reference
6.0

8 Module reference

    8.1 Cache

    8.2 Decode

      8.2.1 Block

      8.2.2 Typography

    8.3 File

    8.4 Pagetree

      8.4.1 Navigation

      8.4.2 Utilities

    8.5 Render

    8.6 Template

    8.7 Tag

    8.8 Top

    8.9 World

 
\ No newline at end of file diff --git a/doc/pollen/Pagetree.html b/doc/pollen/Pagetree.html new file mode 100644 index 0000000..5e5466f --- /dev/null +++ b/doc/pollen/Pagetree.html @@ -0,0 +1,2 @@ + +8.4 Pagetree
6.0

8.4 Pagetree

 (require pollen/pagetree) package: pollen

A pagetree is a hierarchical list of Pollen output files. A pagetree source file has the extension .ptree. A pagetree provides a convenient way of separating the structure of the pages from the page sources, and navigating around this structure.

Pagetrees are made of pagenodes. Usually these pagenodes will be names of output files in your project. (If you think it would’ve been more logical to just call them “pages,” perhaps. When I think of a web page, I think of a file on a disk. Whereas pagenodes may — and often do — refer to files that don’t yet exist.)

Books and other long documents are usually organized in a structured way — at minimum they have a sequence of pages, but more often they have sections with subsequences within. Individual Pollen source files don’t know anything about how they’re connected to other files. In theory, you could maintain this information within each source file. This would be a poor use of human energy. Let the pagetree figure it out.

procedure

(pagetree? possible-pagetree)  boolean?

  possible-pagetree : any/c
Test whether possible-pagetree is a valid pagetree. It must be a txexpr? where all elements are pagenode?, and each is unique within possible-pagetree (not counting the root node).

Examples:

> (pagetree? '(root index.html))

#t

> (pagetree? '(root duplicate.html duplicate.html))

#f

> (pagetree? '(root index.html "string.html"))

#f

> (define nested-ptree '(root 1.html 2.html (3.html 3a.html 3b.html)))
> (pagetree? nested-ptree)

#t

> (pagetree? `(root index.html ,nested-ptree (subsection.html more.html)))

#t

; Nesting a subtree twice creates duplication
> (pagetree? `(root index.html ,nested-ptree (subsection.html ,nested-ptree)))

#f

procedure

(validate-pagetree possible-pagetree)  pagetree?

  possible-pagetree : any/c
Like pagetree?, but raises a descriptive error if possible-pagetree is invalid, and otherwise returns possible-pagetree itself.

Examples:

> (validate-pagetree '(root (mama.html son.html daughter.html) uncle.html))

'(root (mama.html son.html daughter.html) uncle.html)

> (validate-pagetree `(root (,+ son.html daughter.html) uncle.html))

#f

> (validate-pagetree '(root (mama.html son.html son.html) mama.html))

validate-pagetree: items aren’t unique: (son.html mama.html)

procedure

(pagenode? possible-pagenode)  boolean?

  possible-pagenode : any/c
Test whether possible-pagenode is a valid pagenode. A pagenode can be any symbol? that is not whitespace/nbsp? Every leaf of a pagetree is a pagenode. In practice, your pagenodes will likely be names of output files.

Pagenodes are symbols (rather than strings) so that pagetrees will be valid tagged X-expressions, which is a more convenient format for validation & processing.

Examples:

; Three symbols, the third one annoying but valid
> (map pagenode? '(symbol index.html |   silly   |))

'(#t #t #t)

; A number, a string, a txexpr, and a whitespace symbol
> (map pagenode? '(9.999 "index.html" (p "Hello") |    |))

'(#f #f #f #f)

procedure

(pagenodeish? v)  boolean?

  v : any/c
Return #t if v can be converted with ->pagenode.

Example:

> (map pagenodeish? '(9.999 "index.html" |    |))

'(#t #t #f)

procedure

(->pagenode v)  pagenode?

  v : pagenodeish?
Convert v to a pagenode.

Examples:

> (map pagenodeish? '(symbol 9.999 "index.html" |  silly  |))

'(#t #t #t #t)

> (map ->pagenode '(symbol 9.999 "index.html" |  silly  |))

'(symbol |9.999| index.html |  silly  |)

8.4.1 Navigation

parameter

(current-pagetree)  pagetree?

(current-pagetree pagetree)  void?
  pagetree : pagetree?
A parameter that defines the default pagetree used by pagetree navigation functions (e.g., parent-pagenode, chidren, et al.) if another is not explicitly specified. Initialized to #f.

procedure

(parent p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Find the parent pagenode of p within pagetree. Return #f if there isn’t one.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (parent 'son.html)

'mama.html

> (parent "mama.html")

'root

> (parent (parent 'son.html))

'root

> (parent (parent (parent 'son.html)))

#f

procedure

(children p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Find the child pagenodes of p within pagetree. Return #f if there aren’t any.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (children 'mama.html)

'(son.html daughter.html)

> (children 'uncle.html)

#f

> (children 'root)

'(mama.html uncle.html)

> (map children (children 'root))

'((son.html daughter.html) #f)

procedure

(siblings p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Find the sibling pagenodes of p within pagetree. The list will include p itself. But the function will still return #f if pagetree is #f.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (siblings 'son.html)

'(son.html daughter.html)

> (siblings 'daughter.html)

'(son.html daughter.html)

> (siblings 'mama.html)

'(mama.html uncle.html)

procedure

(previous p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)

procedure

(previous* p [pagetree])  (or/c #f (listof pagenode?))

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Return the pagenode immediately before p. For previous*, return all the pagenodes before p, in sequence. In both cases, return #f if there aren’t any pagenodes. The root pagenode is ignored.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (previous 'daughter.html)

'son.html

> (previous 'son.html)

'mama.html

> (previous (previous 'daughter.html))

'mama.html

> (previous 'mama.html)

#f

> (previous* 'daughter.html)

'(mama.html son.html)

> (previous* 'uncle.html)

'(mama.html son.html daughter.html)

procedure

(next p [pagetree])  (or/c #f pagenode?)

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)

procedure

(next* p [pagetree])  (or/c #f (listof pagenode?))

  p : (or/c #f pagenodeish?)
  pagetree : pagetree? = (current-pagetree)
Return the pagenode immediately after p. For next*, return all the pagenodes after p, in sequence. In both cases, return #f if there aren’t any pagenodes. The root pagenode is ignored.

Examples:

> (current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
> (next 'son.html)

'daughter.html

> (next 'daughter.html)

'uncle.html

> (next (next 'son.html))

'uncle.html

> (next 'uncle.html)

#f

> (next* 'mama.html)

'(son.html daughter.html uncle.html)

> (next* 'daughter.html)

'(uncle.html)

8.4.2 Utilities

procedure

(pagetree->list pagetree)  list?

  pagetree : pagetree?
Convert pagetree to a simple list. Equivalent to a pre-order depth-first traversal of pagetree.

procedure

(in-pagetree? pagenode [pagetree])  boolean?

  pagenode : pagenode?
  pagetree : pagetree? = (current-pagetree)
Report whether pagenode is in pagetree.

procedure

(path->pagenode p)  pagenode?

  p : pathish?
Convert path p to a pagenode — meaning, make it relative to current-project-root, run it through ->output-path, and convert it to a symbol. Does not tell you whether the resultant pagenode actually exists in the current pagetree (for that, use in-pagetree?).

 
\ No newline at end of file diff --git a/doc/pollen/Render.html b/doc/pollen/Render.html new file mode 100644 index 0000000..3e28de6 --- /dev/null +++ b/doc/pollen/Render.html @@ -0,0 +1,4 @@ + +8.5 Render
6.0

8.5 Render

 (require pollen/render) package: pollen

Rendering is how Pollen source files get converted into output.

procedure

(render source-path [template-path])  bytes?

  source-path : complete-path?
  template-path : (or/c #f complete-path?) = #f
Renders source-path. The rendering behavior depends on the type of source file:

A [pollen/pre] file is rendered without a template.

A [pollen/markup] or [pollen/markdown] file is rendered with a template. If no template is provided with template-path, Pollen finds one using get-template-for.

Be aware that rendering with a template uses include-template within eval. For complex pages, it can be slow the first time. Caching is used to make subsequent requests faster.

For those panicked at the use of eval, please don’t be. As the author of include-template has already advised, “If you insist on dynamicism” — and yes, I do insist — “there is always eval.

procedure

(render-to-file source-path    
  [template-path    
  output-path])  void?
  source-path : complete-path?
  template-path : (or/c #f complete-path?) = #f
  output-path : (or/c #f complete-path?) = #f
Like render, but saves the file to output-path, overwriting whatever was already there. If no output-path is provided, it’s derived from source-path using ->output-path.

procedure

(render-to-file-if-needed source-path    
  [template-path    
  output-path    
  #:force force-render?])  void?
  source-path : complete-path?
  template-path : (or/c #f complete-path?) = #f
  output-path : (or/c #f complete-path?) = #f
  force-render? : boolean? = #f
Like render-to-file, but the render only happens if one of these conditions exist: +
  1. The force-render? flag — set with the #:force keyword — is #t.

  2. No file exists at output-path. (Thus, an easy way to force a render of a particular output-path is to delete it.)

  3. Either source-path or template-path have changed since the last trip through render.

  4. One or more of the project requires have changed.

If none of these conditions exist, output-path is deemed to be up to date, and the render is skipped.

procedure

(render-batch source-paths ...)  void?

  source-paths : (listof pathish?)
Render multiple source-paths in one go. This can be faster than (for-each render source-paths) if your source-paths rely on a common set of templates. Templates may have their own source files that need to be compiled. If you use render, the templates will be repeatedly (and needlessly) re-compiled. Whereas if you use render-batch, each template will only be compiled once.

procedure

(render-pagetree pagetree)  void?

  pagetree : pagetree?
(render-pagetree pagetree-source)  void?
  pagetree-source : pathish?
Using pagetree, or a pagetree loaded from pagetree-source, render the pages in that pagetree using render-batch.

procedure

(get-template-for source-path)  (or/c #f complete-path?)

  source-path : complete-path?
Find a template file for source-path, with the following priority: +
  1. If the metas for source-path have a key for template, then use the value of this key.

  2. If this key doesn’t exist, or if it points to a nonexistent file, look for a default template in the project directory with the name template.[output extension].pt. Meaning, if source-path is intro.html.pm, the output path would be intro.html, so the default template would be template.html.pt.

  3. If this file doesn’t exist, use the fallback template as a last resort.

This function is called when a template is needed, but a template-path argument is missing (for instance, in render or render-to-file).

 
\ No newline at end of file diff --git a/doc/pollen/System_overview.html b/doc/pollen/System_overview.html new file mode 100644 index 0000000..6619f07 --- /dev/null +++ b/doc/pollen/System_overview.html @@ -0,0 +1,2 @@ + +4 System overview
6.0

4 System overview

A summary of the key components & concepts of the Pollen publishing system and how they fit together. If you’ve completed the Quick tour, this will lend some context to what you saw. The next tutorials will make more sense if you read this first.

4.1 The book is a program

This is the core design principle of Pollen. Consistent with this principle, Pollen adopts the habits of software development in its functionality, workflow, and project management.

  • You are a programmer. Don’t panic. But let’s just admit it — if your book is a program, then you are, in part, programming it. You don’t have to know any programming to start using Pollen. But you’ll have to be willing to learn a few programming ideas. (Those who have programmed other template-based HTML generators may have to forget a few things.)

  • A Pollen project consists of source files + static files. A source file is a file that can be compiled to produce certain output. A static file is usable as it stands (e.g., an SVG file or webfont). Generally, the textual content of your book will live in source files, and other elements will be static files.

  • Source control is a good idea. Because Pollen projects are software projects, they can be easily managed with systems for source control and collaboration, like GitHub. If you’re a writer at heart, don’t fear these systems — they really do make revision & edit tracking easier than it is with Word or PDF files.

4.2 One language, multiple dialects

  • Everything is Racket. The Pollen system is built entirely in the Racket programming language. Some of your source files will be in Racket. Others will be in one of the Pollen language dialects. But under the hood, everything becomes Racket code. So if you plan to do any serious work in Pollen, you’ll want to learn some basics about Racket too (for instance Quick: An Introduction to Racket with Pictures).

  • The Pollen language is based on Scribble. Scribble is a variant of the Racket language that flips the usual programming syntax: instead of code with embedded textual content, a Scribble source file is text with embedded code (an idea borrowed from TeX). The Pollen language is adapted from Scribble. So most things that are true about Scribble are also true about Pollen (see Scribble: The Racket Documentation Tool).

  • The Pollen language is divided into dialects. The Pollen dialects share a common syntax and structure. But they’re different in details that makes them better adapted to certain types of source files (for instance, one dialect of Pollen understands Markdown; the others don’t). You can use whichever suits the task at hand.

4.3 Development environment

The Pollen development environment has two main pieces: the DrRacket code editor, and the Pollen project server.

  • Edit source files with DrRacket. DrRacket is Racket’s GUI code editor. Sure, you can also use a generic text editor. But DrRacket lets you immediately run your source file and see if it works. I know your favorite programming language doesn’t have that. But trust me, it’s very convenient.

  • Render & preview web pages with the Pollen project server. Pollen has a built-in development web server called the project server. After you start the project server, you can preview & test your web pages within a web browser with maximum accuracy. Everything is rendered to static HTML so you can see exactly what you’ll get.

  • One directory for everything. Rather than separating your source files and static files, Pollen keeps them all in one directory so it’s simple to make links between them.

4.4 A special data structure for HTML

X-expression

Tags can be tags

Or tags can be functions

4.5 Preprocessor source files

Lower level of abstraction

Work directly

Text output

Any kind of file!

4.6 Templated source files

Higher level of abstraction

Work indirectly

X-expression output

Markdown

Markup

Templates

4.7 Utility source files

Scribble

Null

4.8 Pagetrees

Navigation

Hierarchy

Subsetting

Build script

4.9 Build & deploy

Pollen is not a production server

Render & clone

 
\ No newline at end of file diff --git a/doc/pollen/Tag.html b/doc/pollen/Tag.html new file mode 100644 index 0000000..b89714d --- /dev/null +++ b/doc/pollen/Tag.html @@ -0,0 +1,2 @@ + +8.7 Tag
6.0

8.7 Tag

 (require pollen/tag) package: pollen

Convenience functions for working with tags.

procedure

(make-tag-function id)  (-> txexpr?)

  id : txexpr-tag?
Make a tag function for id. As arguments, a tag function takes an optional set of X-expression attributes (txexpr-attrs?) followed by X-expression elements (txexpr-elements?). From these, the tag function creates a tagged X-expression using id as the tag.

Examples:

> (require pollen/tag)
> (define beaucoup (make-tag-function 'em))
> (beaucoup "Bonjour")

'(em "Bonjour")

> (beaucoup '((id "greeting")) "Bonjour")

'(em ((id "greeting")) "Bonjour")

Entering attributes this way can be cumbersome. So for convenience, a tag function provides an alternative: any symbol + string pairs at the front of your expression will be interpreted as attributes, if the symbols are followed by a colon. If you leave out the colon, the symbols will be interpreted as part of the content of the tag.

Examples:

> (require pollen/tag)
> (define beaucoup (make-tag-function 'em))
> (beaucoup 'id: "greeting" 'class: "large" "Bonjour")

'(em ((id "greeting") (class "large")) "Bonjour")

; Don't forget the colons
> (beaucoup 'id "greeting" 'class "large" "Bonjour")

'(em id "greeting" class "large" "Bonjour")

; Don't forget to provide a value for each attribute
> (beaucoup 'id: 'class: "large" "Bonjour")

'(em id: class: "large" "Bonjour")

Pollen also uses this function to provide the default behavior for undefined tags. See #%top.

 
\ No newline at end of file diff --git a/doc/pollen/Template.html b/doc/pollen/Template.html new file mode 100644 index 0000000..8a15da8 --- /dev/null +++ b/doc/pollen/Template.html @@ -0,0 +1,2 @@ + +8.6 Template
6.0

8.6 Template

 (require pollen/template) package: pollen

Convenience functions for templates. These are automatically imported into the eval environment when rendering with a template (see render).

This module also provides everything from sugar/coerce/value.

procedure

(->html xexpr)  string?

  xexpr : xexpr?
Convert xexpr to an HTML string. Similar to xexpr->string, but consistent with the HTML spec, text that appears within script or style blocks will not be escaped.

Examples:

> (define tx '(root (script "3 > 2") "Why is 3 > 2?"))
> (xexpr->string tx)

"<root><script>3 &gt; 2</script>Why is 3 &gt; 2?</root>"

> (->html tx)

"<root><script>3 > 2</script>Why is 3 &gt; 2?</root>"

Be careful not to pass existing HTML strings into this function, because the angle brackets will be escaped. Fine if that’s what you want, but you probably don’t.

Examples:

> (define tx '(p "You did" (em "what?")))
> (->html tx)

"<p>You did<em>what?</em></p>"

> (->html (->html tx))

"&lt;p&gt;You did&lt;em&gt;what?&lt;/em&gt;&lt;/p&gt;"

procedure

(select key value-source)  (or/c #f txexpr-element?)

  key : symbolish?
  value-source : (or/c hash? txexpr? pagenode? pathish?)

procedure

(select* key value-source)  (or/c #f (listof txexpr-element?))

  key : symbolish?
  value-source : (or/c hash? txexpr? pagenode? pathish?)
Find matches for key in value-source, first by looking in its metas (using select-from-metas) and then by looking in its doc (using select-from-doc). With select, you get the first result; with select*, you get them all. In both cases, you get #f if there are no matches.

procedure

(select-from-metas key meta-source)  (or/c #f txexpr-element?)

  key : symbolish?
  meta-source : (or/c hash? pagenodeish? pathish?)
Look up the value of key in meta-source. The meta-source argument can be either a set of metas (i.e., a hash) or a pagenode?, from which metas are pulled. If no value exists for key, you get #f.

Examples:

> (module ice-cream pollen/markup
  '(div (question "Flavor?")
    (answer "Chocolate chip") (answer "Maple walnut"))
    '(meta ((template "sub.xml.pt")))
    '(meta ((target "print"))))
; Import doc & metas from 'ice-cream submodule
> (require 'ice-cream)
> (select-from-metas 'template  metas)

"sub.xml.pt"

> ('target . select-from-metas . metas)

"print"

> (select-from-metas 'nonexistent-key metas)

#f

procedure

(select-from-doc key doc-source)  (or/c #f txexpr-element?)

  key : symbolish?
  doc-source : (or/c txexpr? pagenodeish? pathish?)
Look up the value of key in doc-source. The doc-source argument can be either be a doc (i.e., a txexpr) or a pagenode?, from which doc is pulled. If no value exists for key, you get #f.

Examples:

> (module gelato pollen/markup
  '(div (question "Flavor?")
    (answer "Nocciola") (answer "Pistachio"))
    '(meta ((template "sub.xml.pt")))
    '(meta ((target "print"))))
; Import doc & metas from 'gelato submodule
> (require 'gelato)
> (select-from-doc 'question  doc)

'("Flavor?")

> ('answer . select-from-doc . doc)

'("Nocciola" "Pistachio")

> (select-from-doc 'nonexistent-key doc)

#f

 
\ No newline at end of file diff --git a/doc/pollen/Top.html b/doc/pollen/Top.html new file mode 100644 index 0000000..fde75dd --- /dev/null +++ b/doc/pollen/Top.html @@ -0,0 +1,2 @@ + +8.8 Top
6.0

8.8 Top

 (require pollen/top) package: pollen

You’ll probably never invoke this module directly. But it’s implicitly imported into every Pollen markup file. And if you don’t know what it does, you might end up surprised by some of the behavior you get.

syntax

(#%top . id)

In standard Racket, #%top is the function of last resort, called when id is not bound to any value. As such, it typically reports a syntax error.

Examples:

; Let's call em without defining it
> (em "Bonjour")

em: undefined;

 cannot reference undefined identifier

; (em "Bonjour") is being converted to ((#%top . em) "Bonjour")
; So calling ((#%top . em) "Bonjour") will give the same result
> ((#%top . em) "Bonjour")

em: undefined;

 cannot reference undefined identifier

In the Pollen markup environment, however, this behavior is annoying. Because when you’re writing X-expressions, you don’t necessarily want to define all your tags ahead of time.

So Pollen redefines #%top. For convenience, Pollen’s version of #%top assumes that an undefined tag should just refer to an X-expression beginning with that tag (and uses make-tag-function to provide this behavior):

Examples:

; Again, let's call em without defining it, but using pollen/top
> (require pollen/top)
> (em "Bonjour")

'(em "Bonjour")

; (em "Bonjour") is still being converted to ((#%top . em) "Bonjour")
; But now, ((#%top . em) "Bonjour") gives a different result
> ((#%top . em) "Bonjour")

'(em "Bonjour")

The good news is that this behavior means you use any tag you want in your markup without defining it in advance. You can still attach a function to the tag later, which will automatically supersede #%top.

Examples:

> (define (em x) `(span ((style "font-size:100px")) ,x))
> (em "Bonjour")

'(span ((style "font-size:100px")) "Bonjour")

The bad news is that you’ll never get an “undefined identifier” error. These undefined identifiers will happily sail through and be converted to tags.

Examples:

> (require pollen/top)
> (define (em . xs) `(span ((style "font-size:100px")) ,@xs))
; There's a typo in my tag
> (erm "Bonjour")

'(erm "Bonjour")

This isn’t a bug. It’s just a natural consequence of how Pollen’s #%top works. It can, however, make debugging difficult sometimes. Let’s suppose my markup depends on very-important-function, which I don’t import correctly.

Examples:

> (require pollen/top)
> (module vif racket/base
      (define (very-important-function . xs) `(secrets-of-universe ,@xs)))
; Forgot to (require 'vif)
> (very-important-function "Bonjour")

'(very-important-function "Bonjour")

So the undefined-function bug goes unreported. Again, that’s not a bug in Pollen — there’s just no way for it to tell the difference between an identifier that’s deliberately undefined and one that’s inadvertently undefined. If you want to guarantee that you’re invoking a defined identifier, use def/c.

syntax

(def/c id)

Invoke id if it’s a defined identifier, otherwise raise an error. This form reverses the behavior of #%top (in other words, it restores default Racket behavior).

Recall this example from before. In standard Racket, you get an undefined-identifier error.

Examples:

> (module vif racket/base
      (define (very-important-function . xs) `(secrets-of-universe ,@xs)))
; Forgot to (require 'vif)
> (very-important-function "Bonjour")

very-important-function: undefined;

 cannot reference undefined identifier

But with pollen/top, the issue is not treated as an error.

Examples:

> (require pollen/top)
> (module vif racket/base
      (define (very-important-function . xs) `(secrets-of-universe ,@xs)))
; Forgot to (require 'vif)
> (very-important-function "Bonjour")

'(very-important-function "Bonjour")

By adding def/c, we restore the usual behavior, guaranteeing that we get the defined version of very-important-function or nothing.

Examples:

> (require pollen/top)
> (module vif racket/base
      (define (very-important-function . xs) `(secrets-of-universe ,@xs)))
; Forgot to (require 'vif)
> ((def/c very-important-function) "Bonjour")

very-important-function: undefined;

 cannot reference undefined identifier

 
\ No newline at end of file diff --git a/doc/pollen/Using_raco_pollen.html b/doc/pollen/Using_raco_pollen.html new file mode 100644 index 0000000..f76e11a --- /dev/null +++ b/doc/pollen/Using_raco_pollen.html @@ -0,0 +1,2 @@ + +5 Using raco pollen
6.0

5 Using raco pollen

Racket provides centralized command-line options through raco (short for racket command, see raco: Racket Command-Line Tools).

Once you install Pollen, you can access the following Pollen-specific commands through raco using the subcommand raco pollen.

5.1 Making sure raco pollen works

Open a terminal window and type:

> raco pollen test

If raco pollen is installed correctly, you’ll see:

raco pollen is installed correctly

But if you get:

raco: Unrecognized command: pollen

You’ll need to fix the problem before proceeding, most likely by reinstalling Pollen (see Installation).

5.2 raco pollen

Same as raco pollen help.

5.3 raco pollen help

Displays a list of available commands.

5.4 raco pollen start

Starts the project server from the current directory using the default port, which is the value of the parameter world:current-server-port (by default, port 8080).

This command can be invoked with two optional arguments.

raco pollen start path will start the project server in path rather than the current directory.

> raco pollen start ~/path/to/project/

raco pollen start path port will start the project server in path using port rather than world:current-server-port. This is useful if you want to have multiple project servers running simultaneously.

> raco pollen start ~/path/to/project/

> raco pollen start ~/path/to/project/scribblings 8088

If you want to start in the current directory but with a different port, use . as the path:

> raco pollen start . 8088

5.5 raco pollen render

Renders all preprocessor source files and then all pagetree files found in the current directory.

This command can be invoked with extra arguments.

raco pollen render directory will render the preprocessor source files and pagetree files in the specified directory.

Alternatively, the command can take a variable number of path arguments. raco pollen render path... will render only the paths specified in path.... Consistent with the usual command-line idiom, this can be a single path, a list of paths, or a pattern:

> raco pollen render foo.html.pm

> raco pollen render foo.html.pm bar.html.pm zam.css.pp

> raco pollen render *.html.pm

5.6 raco pollen clone

Makes a copy of the project directory on the desktop, and removes any source files or other Pollen-related files.

raco pollen clobe directory-path will perform the same copying and filtering, but using directory-path as the destination rather than the desktop.

 
\ No newline at end of file diff --git a/doc/pollen/World.html b/doc/pollen/World.html new file mode 100644 index 0000000..0e1992a --- /dev/null +++ b/doc/pollen/World.html @@ -0,0 +1,12 @@ + +8.9 World
6.0

8.9 World

 (require pollen/world) package: pollen

A set of global values and parameters that are used throughout the Pollen system. If you don’t like the defaults I’ve picked, change them.

All identifiers are exported with the prefix world:, and are so documented below.

A parameter that sets the HTTP port for the project server. Initialized to world:default-port, which defaults to 8080.

The two exports from a compiled Pollen source file. Initialized to 'doc and 'metas, respectively.

File implicitly required into every Pollen source file from its directory. Initialized to "project-require.rkt".

A parameter that determines whether the world:project-require file is checked for changes on every pass through render. (Can be faster to turn this off if you don’t need it.) Initialized to #t.

Name of directory where server support files live. Initialized to "server-extras".

A parameter that reports the path to the directory of support files for the project server. Initialized to #f, but set to a proper value when the server runs.

File extensions for Pollen source files, initialized to the following values:

world:preproc-source-ext = pp +
world:markup-source-ext = pm +
world:markdown-source-ext = pmd +
world:null-source-ext = p +
world:pagetree-source-ext = ptree +
world:template-source-ext = pt +
world:scribble-source-ext = scrbl

File extensions that are eligible for decoding.

Mode indicators for the Pollen reader and parser. Initialized to the following values:

world:mode-auto = auto +
world:mode-preproc = pre +
world:mode-markup = markup +
world:mode-markdown = markdown +
world:mode-pagetree = ptree

Pagetree that Pollen dashboard loads by default in each directory. Initialized to "index.ptree".

Name of the root node in a decoded pagetree. It’s ignored by the code, so its only role is to clue you in that you’re looking at something that came out of the pagetree decoder. Initialized to 'pagetree-root.

The magic character that indicates a Pollen command, function, or variable. Initialized to #\◊.

Prefix of the default template. Initialized to "template".

Name of the fallback template (i.e., the template used to render a Pollen markup file when no other template can be found). Initialized to "fallback.html.pt".

Meta key used to store a template name for that particular source file. Initialized to 'template.

Default separators used in decoding. The first two are initialized to "\n"; the third to "\n\n".

CSS file used for the dashboard. Initialized to "poldash.css".

Paths not shown in the Pollen dashboard.

 
\ No newline at end of file diff --git a/doc/pollen/blueboxes.rktd b/doc/pollen/blueboxes.rktd new file mode 100644 index 0000000..de3f350 --- /dev/null +++ b/doc/pollen/blueboxes.rktd @@ -0,0 +1,334 @@ +5896 +((3) 0 () 8 ((q lib "pollen/world.rkt") (q lib "pollen/pagetree.rkt") (q lib "pollen/decode.rkt") (q lib "pollen/file.rkt") (q lib "pollen/template.rkt") (q lib "pollen/cache.rkt") (q lib "pollen/render.rkt") (q lib "pollen/top.rkt")) () (h ! (equal) ((c def c (c (? . 0) q world:pagetree-source-ext)) q (9375 . 2)) ((c def c (c (? . 4) q select)) q (7838 . 4)) ((c def c (c (? . 5) q current-cache)) q (0 . 4)) ((c def c (c (? . 1) q pagetree->list)) q (6265 . 3)) ((c def c (c (? . 2) q smart-quotes)) q (2337 . 3)) ((c def c (c (? . 6) q render-to-file)) q (6694 . 7)) ((c def c (c (? . 0) q world:mode-preproc)) q (9596 . 2)) ((c def c (c (? . 1) q next)) q (5966 . 4)) ((c def c (c (? . 3) q has-preproc-source?)) q (3661 . 3)) ((c def c (c (? . 0) q world:markdown-source-ext)) q (9291 . 2)) ((c def c (c (? . 0) q world:paragraph-separator)) q (10074 . 2)) ((c def c (c (? . 2) q smart-dashes)) q (2400 . 3)) ((c def c (c (? . 0) q world:dashboard-css)) q (10118 . 2)) ((c def c (c (? . 0) q world:server-extras-dir)) q (9039 . 2)) ((c def c (c (? . 1) q previous)) q (5659 . 4)) ((c def c (c (? . 3) q ->template-source-path)) q (4455 . 3)) ((c def c (c (? . 1) q children)) q (5363 . 4)) ((c def c (c (? . 2) q whitespace/nbsp?)) q (2275 . 3)) ((c def c (c (? . 4) q ->html)) q (7778 . 3)) ((c def c (c (? . 0) q world:project-require)) q (8848 . 2)) ((c def c (c (? . 3) q preproc-source?)) q (3296 . 3)) ((c def c (c (? . 0) q world:current-server-extras-path)) q (9081 . 4)) ((c def c (c (? . 0) q world:template-source-ext)) q (9419 . 2)) ((c def c (c (? . 5) q reset-cache)) q (279 . 2)) ((c def c (c (? . 2) q whitespace?)) q (2218 . 3)) ((c def c (c (? . 1) q siblings)) q (5511 . 4)) ((c def c (c (? . 4) q select*)) q (7997 . 4)) ((c def c (c (? . 2) q detect-linebreaks)) q (2463 . 8)) ((c def c (c (? . 0) q world:main-pollen-export)) q (8762 . 2)) ((c def c (c (? . 0) q world:default-pagetree)) q (9745 . 2)) ((c def c (c (? . 0) q world:meta-pollen-export)) q (8805 . 2)) ((q def ((lib "pollen/tag.rkt") make-tag-function)) q (8489 . 3)) ((c def c (c (? . 2) q register-block-tag)) q (2088 . 3)) ((c def c (c (? . 0) q world:paths-excluded-from-dashboard)) q (10156 . 2)) ((c def c (c (? . 1) q path->pagenode)) q (6478 . 3)) ((c def c (c (? . 3) q has/is-scribble-source?)) q (4253 . 3)) ((c def c (c (? . 4) q select-from-doc)) q (8329 . 4)) ((c def c (c (? . 0) q world:current-server-port)) q (8643 . 4)) ((c def c (c (? . 3) q has-template-source?)) q (3790 . 3)) ((c form c (c (? . 7) q #%top)) q (8565 . 2)) ((c def c (c (? . 3) q ->scribble-source-path)) q (4587 . 3)) ((c def c (c (? . 1) q pagetree?)) q (4714 . 3)) ((c def c (c (? . 6) q render)) q (6542 . 4)) ((c def c (c (? . 3) q has-null-source?)) q (3856 . 3)) ((c def c (c (? . 2) q decode)) q (389 . 26)) ((c def c (c (? . 3) q template-source?)) q (3417 . 3)) ((c def c (c (? . 0) q world:fallback-template)) q (9914 . 2)) ((c def c (c (? . 0) q world:check-project-requires-in-render?)) q (8888 . 4)) ((c def c (c (? . 0) q world:mode-auto)) q (9562 . 2)) ((c def c (c (? . 1) q in-pagetree?)) q (6340 . 4)) ((c def c (c (? . 0) q world:decodable-extensions)) q (9507 . 2)) ((c def c (c (? . 6) q get-template-for)) q (7669 . 3)) ((c def c (c (? . 0) q world:mode-markup)) q (9633 . 2)) ((c def c (c (? . 3) q has/is-markup-source?)) q (4052 . 3)) ((c def c (c (? . 0) q world:newline)) q (9998 . 2)) ((c def c (c (? . 1) q pagenode?)) q (4897 . 3)) ((c def c (c (? . 0) q world:mode-markdown)) q (9669 . 2)) ((c def c (c (? . 3) q null-source?)) q (3479 . 3)) ((c def c (c (? . 0) q world:linebreak-separator)) q (10030 . 2)) ((c def c (c (? . 0) q world:pagetree-root-node)) q (9786 . 2)) ((c def c (c (? . 6) q render-to-file-if-needed)) q (6976 . 9)) ((c def c (c (? . 2) q block-txexpr?)) q (2159 . 3)) ((c def c (c (? . 3) q has-scribble-source?)) q (3918 . 3)) ((c def c (c (? . 6) q render-batch)) q (7419 . 3)) ((c def c (c (? . 5) q cache-ref)) q (314 . 3)) ((c def c (c (? . 1) q next*)) q (6110 . 4)) ((c def c (c (? . 3) q pagetree-source?)) q (3599 . 3)) ((c def c (c (? . 1) q parent)) q (5217 . 4)) ((c def c (c (? . 3) q has-markup-source?)) q (3726 . 3)) ((c def c (c (? . 3) q ->null-source-path)) q (4523 . 3)) ((c def c (c (? . 5) q cached-require)) q (89 . 4)) ((c def c (c (? . 0) q world:default-template-prefix)) q (9866 . 2)) ((c def c (c (? . 2) q detect-paragraphs)) q (2789 . 11)) ((c def c (c (? . 0) q world:default-port)) q (8605 . 2)) ((c def c (c (? . 1) q pagenodeish?)) q (4984 . 3)) ((c def c (c (? . 0) q world:command-marker)) q (9829 . 2)) ((c def c (c (? . 0) q world:markup-source-ext)) q (9249 . 2)) ((c def c (c (? . 3) q ->preproc-source-path)) q (4322 . 3)) ((c def c (c (? . 2) q project-block-tags)) q (1945 . 4)) ((c def c (c (? . 1) q current-pagetree)) q (5106 . 4)) ((c def c (c (? . 0) q world:mode-pagetree)) q (9707 . 2)) ((c def c (c (? . 6) q render-pagetree)) q (7514 . 5)) ((c def c (c (? . 1) q previous*)) q (5807 . 4)) ((c def c (c (? . 4) q select-from-metas)) q (8167 . 4)) ((c def c (c (? . 3) q has/is-null-source?)) q (4188 . 3)) ((c def c (c (? . 3) q ->output-path)) q (4655 . 3)) ((c form c (c (? . 7) q def/c)) q (8586 . 2)) ((c def c (c (? . 0) q world:scribble-source-ext)) q (9463 . 2)) ((c def c (c (? . 5) q make-cache)) q (245 . 2)) ((c def c (c (? . 0) q world:template-meta-key)) q (9956 . 2)) ((c def c (c (? . 3) q has/is-preproc-source?)) q (3984 . 3)) ((c def c (c (? . 3) q scribble-source?)) q (3537 . 3)) ((c def c (c (? . 3) q ->markup-source-path)) q (4389 . 3)) ((c def c (c (? . 3) q markup-source?)) q (3357 . 3)) ((c def c (c (? . 1) q ->pagenode)) q (5042 . 3)) ((c def c (c (? . 0) q world:null-source-ext)) q (9335 . 2)) ((c def c (c (? . 3) q has/is-template-source?)) q (4119 . 3)) ((c def c (c (? . 0) q world:preproc-source-ext)) q (9206 . 2)) ((c def c (c (? . 1) q validate-pagetree)) q (4801 . 3)))) +parameter +(current-cache) -> hash? +(current-cache hash) -> void? +  hash : hash? +procedure +(cached-require source-path key) -> (or/c txexpr? hash? integer?) +  source-path : pathish? +  key : (or/c 'doc 'metas 'mod-time) +procedure +(make-cache) -> hash? +procedure +(reset-cache) -> void? +procedure +(cache-ref source-path) -> hash? +  source-path : pathish? +procedure +(decode  tagged-xexpr       +   [#:txexpr-tag-proc txexpr-tag-proc       +    #:txexpr-attrs-proc txexpr-attrs-proc       +    #:txexpr-elements-proc txexpr-elements-proc      +    #:block-txexpr-proc block-txexpr-proc       +    #:inline-txexpr-proc inline-txexpr-proc       +    #:string-proc string-proc       +    #:symbol-proc symbol-proc       +    #:valid-char-proc valid-char-proc       +    #:cdata-proc cdata-proc       +    #:exclude-tags tags-to-exclude])  -> txexpr? +  tagged-xexpr : txexpr? +  txexpr-tag-proc : (txexpr-tag? . -> . txexpr-tag?) +     = (λ(tag) tag) +  txexpr-attrs-proc : (txexpr-attrs? . -> . txexpr-attrs?) +     = (λ(attrs) attrs) +  txexpr-elements-proc : (txexpr-elements? . -> . txexpr-elements?) +     = (λ(elements) elements) +  block-txexpr-proc : (block-txexpr? . -> . xexpr?) = (λ(tx) tx) +  inline-txexpr-proc : (txexpr? . -> . xexpr?) = (λ(tx) tx) +  string-proc : (string? . -> . xexpr?) = (λ(str) str) +  symbol-proc : (symbol? . -> . xexpr?) = (λ(sym) sym) +  valid-char-proc : (valid-char? . -> . xexpr?) = (λ(vc) vc) +  cdata-proc : (cdata? . -> . xexpr?) = (λ(cdata) cdata) +  tags-to-exclude : (listof symbol?) = null +parameter +(project-block-tags) -> (listof txexpr-tag?) +(project-block-tags block-tags) -> void? +  block-tags : (listof txexpr-tag?) +procedure +(register-block-tag tag) -> void? +  tag : txexpr-tag? +procedure +(block-txexpr? v) -> boolean? +  v : any/c +procedure +(whitespace? v) -> boolean? +  v : any/c +procedure +(whitespace/nbsp? v) -> boolean? +  v : any/c +procedure +(smart-quotes str) -> string? +  str : string? +procedure +(smart-dashes str) -> string? +  str : string? +procedure +(detect-linebreaks  tagged-xexpr-elements   +   [#:separator linebreak-sep  +    #:insert linebreak])   + -> txexpr-elements? +  tagged-xexpr-elements : txexpr-elements? +  linebreak-sep : string? = world:linebreak-separator +  linebreak : xexpr? = '(br) +procedure +(detect-paragraphs  elements   +   [#:separator paragraph-sep   +    #:tag paragraph-tag   +    #:linebreak-proc linebreak-proc])  + -> txexpr-elements? +  elements : txexpr-elements? +  paragraph-sep : string? = world:paragraph-separator +  paragraph-tag : symbol? = 'p +  linebreak-proc : (txexpr-elements? . -> . txexpr-elements?) +     = detect-linebreaks +procedure +(preproc-source? v) -> boolean? +  v : any/c +procedure +(markup-source? v) -> boolean? +  v : any/c +procedure +(template-source? v) -> boolean? +  v : any/c +procedure +(null-source? v) -> boolean? +  v : any/c +procedure +(scribble-source? v) -> boolean? +  v : any/c +procedure +(pagetree-source? v) -> boolean? +  v : any/c +procedure +(has-preproc-source? v) -> boolean? +  v : any/c +procedure +(has-markup-source? v) -> boolean? +  v : any/c +procedure +(has-template-source? v) -> boolean? +  v : any/c +procedure +(has-null-source? v) -> boolean? +  v : any/c +procedure +(has-scribble-source? v) -> boolean? +  v : any/c +procedure +(has/is-preproc-source? v) -> boolean? +  v : any/c +procedure +(has/is-markup-source? v) -> boolean? +  v : any/c +procedure +(has/is-template-source? v) -> boolean? +  v : any/c +procedure +(has/is-null-source? v) -> boolean? +  v : any/c +procedure +(has/is-scribble-source? v) -> boolean? +  v : any/c +procedure +(->preproc-source-path p) -> path? +  p : pathish? +procedure +(->markup-source-path p) -> path? +  p : pathish? +procedure +(->template-source-path p) -> path? +  p : pathish? +procedure +(->null-source-path p) -> path? +  p : pathish? +procedure +(->scribble-source-path p) -> path? +  p : pathish? +procedure +(->output-path p) -> path? +  p : pathish? +procedure +(pagetree? possible-pagetree) -> boolean? +  possible-pagetree : any/c +procedure +(validate-pagetree possible-pagetree) -> pagetree? +  possible-pagetree : any/c +procedure +(pagenode? possible-pagenode) -> boolean? +  possible-pagenode : any/c +procedure +(pagenodeish? v) -> boolean? +  v : any/c +procedure +(->pagenode v) -> pagenode? +  v : pagenodeish? +parameter +(current-pagetree) -> pagetree? +(current-pagetree pagetree) -> void? +  pagetree : pagetree? +procedure +(parent p [pagetree]) -> (or/c #f pagenode?) +  p : (or/c #f pagenodeish?) +  pagetree : pagetree? = (current-pagetree) +procedure +(children p [pagetree]) -> (or/c #f pagenode?) +  p : (or/c #f pagenodeish?) +  pagetree : pagetree? = (current-pagetree) +procedure +(siblings p [pagetree]) -> (or/c #f pagenode?) +  p : (or/c #f pagenodeish?) +  pagetree : pagetree? = (current-pagetree) +procedure +(previous p [pagetree]) -> (or/c #f pagenode?) +  p : (or/c #f pagenodeish?) +  pagetree : pagetree? = (current-pagetree) +procedure +(previous* p [pagetree]) -> (or/c #f (listof pagenode?)) +  p : (or/c #f pagenodeish?) +  pagetree : pagetree? = (current-pagetree) +procedure +(next p [pagetree]) -> (or/c #f pagenode?) +  p : (or/c #f pagenodeish?) +  pagetree : pagetree? = (current-pagetree) +procedure +(next* p [pagetree]) -> (or/c #f (listof pagenode?)) +  p : (or/c #f pagenodeish?) +  pagetree : pagetree? = (current-pagetree) +procedure +(pagetree->list pagetree) -> list? +  pagetree : pagetree? +procedure +(in-pagetree? pagenode [pagetree]) -> boolean? +  pagenode : pagenode? +  pagetree : pagetree? = (current-pagetree) +procedure +(path->pagenode p) -> pagenode? +  p : pathish? +procedure +(render source-path [template-path]) -> bytes? +  source-path : complete-path? +  template-path : (or/c #f complete-path?) = #f +procedure +(render-to-file  source-path       +   [template-path      +    output-path]) -> void? +  source-path : complete-path? +  template-path : (or/c #f complete-path?) = #f +  output-path : (or/c #f complete-path?) = #f +procedure +(render-to-file-if-needed  source-path       +   [template-path       +    output-path       +    #:force force-render?]) -> void? +  source-path : complete-path? +  template-path : (or/c #f complete-path?) = #f +  output-path : (or/c #f complete-path?) = #f +  force-render? : boolean? = #f +procedure +(render-batch source-paths ...) -> void? +  source-paths : (listof pathish?) +procedure +(render-pagetree pagetree) -> void? +  pagetree : pagetree? +(render-pagetree pagetree-source) -> void? +  pagetree-source : pathish? +procedure +(get-template-for source-path) -> (or/c #f complete-path?) +  source-path : complete-path? +procedure +(->html xexpr) -> string? +  xexpr : xexpr? +procedure +(select key value-source) -> (or/c #f txexpr-element?) +  key : symbolish? +  value-source : (or/c hash? txexpr? pagenode? pathish?) +procedure +(select* key value-source) -> (or/c #f (listof txexpr-element?)) +  key : symbolish? +  value-source : (or/c hash? txexpr? pagenode? pathish?) +procedure +(select-from-metas key meta-source) -> (or/c #f txexpr-element?) +  key : symbolish? +  meta-source : (or/c hash? pagenodeish? pathish?) +procedure +(select-from-doc key doc-source) -> (or/c #f txexpr-element?) +  key : symbolish? +  doc-source : (or/c txexpr? pagenodeish? pathish?) +procedure +(make-tag-function id) -> (-> txexpr?) +  id : txexpr-tag? +syntax +(#%top . id) +syntax +(def/c id) +value +world:default-port : integer? +parameter +(world:current-server-port) -> integer? +(world:current-server-port port) -> void? +  port : integer? +value +world:main-pollen-export : symbol? +value +world:meta-pollen-export : symbol? +value +world:project-require : string? +parameter +(world:check-project-requires-in-render?) -> boolean? +(world:check-project-requires-in-render? check?) -> void? +  check? : boolean? +value +world:server-extras-dir : string? +parameter +(world:current-server-extras-path) -> path? +(world:current-server-extras-path dir) -> void? +  dir : path? +value +world:preproc-source-ext : symbol? +value +world:markup-source-ext : symbol? +value +world:markdown-source-ext : symbol? +value +world:null-source-ext : symbol? +value +world:pagetree-source-ext : symbol? +value +world:template-source-ext : symbol? +value +world:scribble-source-ext : symbol? +value +world:decodable-extensions : (listof symbol?) +value +world:mode-auto : symbol? +value +world:mode-preproc : symbol? +value +world:mode-markup : symbol? +value +world:mode-markdown : symbol? +value +world:mode-pagetree : symbol? +value +world:default-pagetree : string? +value +world:pagetree-root-node : symbol? +value +world:command-marker : char? +value +world:default-template-prefix : string? +value +world:fallback-template : string? +value +world:template-meta-key : symbol? +value +world:newline : string? +value +world:linebreak-separator : string? +value +world:paragraph-separator : string? +value +world:dashboard-css : string? +value +world:paths-excluded-from-dashboard : (listof path?) diff --git a/doc/pollen/doc-index.html b/doc/pollen/doc-index.html new file mode 100644 index 0000000..e10e106 --- /dev/null +++ b/doc/pollen/doc-index.html @@ -0,0 +1,2 @@ + +Index

Index

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

 

“Now you have two problems”
#%top
->html
->markup-source-path
->null-source-path
->output-path
->pagenode
->preproc-source-path
->scribble-source-path
->template-source-path
A special data structure for HTML
Acknowledgments
Any command is valid
Backstory
Block
block-txexpr?
Build & deploy
Cache
cache-ref
cached-require
children
Command syntax using ◊
Creating a source file
current-cache
current-pagetree
Custom exports
Decode
decode
def/c
detect-linebreaks
detect-paragraphs
Development environment
Enter Racket
File
File formats
Further reading
get-template-for
has-markup-source?
has-null-source?
has-preproc-source?
has-scribble-source?
has-template-source?
has/is-markup-source?
has/is-null-source?
has/is-preproc-source?
has/is-scribble-source?
has/is-template-source?
in-pagetree?
Inserting a comment
Inserting the value of a variable
Installation
Intermission
Invoking other functions
Invoking tag functions
License & source code
make-cache
make-tag-function
Making sure raco pollen works
Markdown (.pmd extension)
Markdown mode
Markup (.pm extension)
Markup mode
markup-source?
Module reference
Naming, saving, and rendering a source file
Navigation
next
next*
Null (.p extension)
null-source?
One language, multiple dialects
pagenode?
pagenodeish?
Pagetree
Pagetree (.ptree extension)
pagetree->list
pagetree-source?
pagetree?
Pagetrees
parent
path->pagenode
pollen
Pollen as a preprocessor
pollen/cache
pollen/decode
pollen/file
pollen/markdown
pollen/markup
pollen/pagetree
pollen/pre
pollen/ptree
pollen/render
pollen/tag
pollen/template
pollen/top
pollen/world
Pollen: the book is a program
preproc-source?
Preprocessor (.pp extension)
Preprocessor source files
previous
previous*
project-block-tags
PS for Scribble users
Quick tour
raco pollen
raco pollen clone
raco pollen help
raco pollen render
raco pollen start
register-block-tag
Render
render
render-batch
render-pagetree
render-to-file
render-to-file-if-needed
reset-cache
Rethinking the solution for digital books
Running a source file
Scribble (.scrbl extension)
scribble-source?
select
select*
select-from-doc
select-from-metas
siblings
smart-dashes
smart-quotes
Source formats
Standard exports
System overview
Tag
Template
template-source?
Templated source files
Templates
The better idea: a programming model
The book is a program
The command name
The end of the beginning
The golden rule
The lozenge glyph (◊)
The project server
The project-require.rkt file
The Racket arguments
The text argument
The two command modes: text mode & Racket mode
Top
Typography
Using raco pollen
Utilities
Utility formats
Utility source files
validate-pagetree
Web development and its discontents
What is Pollen?
whitespace/nbsp?
whitespace?
World
world:check-project-requires-in-render?
world:command-marker
world:current-server-extras-path
world:current-server-port
world:dashboard-css
world:decodable-extensions
world:default-pagetree
world:default-port
world:default-template-prefix
world:fallback-template
world:linebreak-separator
world:main-pollen-export
world:markdown-source-ext
world:markup-source-ext
world:meta-pollen-export
world:mode-auto
world:mode-markdown
world:mode-markup
world:mode-pagetree
world:mode-preproc
world:newline
world:null-source-ext
world:pagetree-root-node
world:pagetree-source-ext
world:paragraph-separator
world:paths-excluded-from-dashboard
world:preproc-source-ext
world:project-require
world:scribble-source-ext
world:server-extras-dir
world:template-meta-key
world:template-source-ext
◊ command overview

 
\ No newline at end of file diff --git a/doc/pollen/in.sxref b/doc/pollen/in.sxref new file mode 100644 index 0000000..31e2be2 Binary files /dev/null and b/doc/pollen/in.sxref differ diff --git a/doc/pollen/index.html b/doc/pollen/index.html new file mode 100644 index 0000000..02247f6 --- /dev/null +++ b/doc/pollen/index.html @@ -0,0 +1,3 @@ + +Pollen: the book is a program
6.0

Pollen: the book is a program

Matthew Butterick <mb@mbtype.com>

 #lang pollen package: pollen

Pollen is a publishing system that helps authors create beautiful and functional web-based books. Pollen includes tools for writing, designing, programming, testing, and publishing.

I used Pollen to create my book Butterick’s Practical Typography. Sure, go take a look. Is it better than the last digital book you encountered? Yes it is. Would you like your book to look like that? If so, keep reading.

At the core of Pollen is an argument: +
  • First, that digital books should be the best books we’ve ever had. So far, they’re not even close.

  • Second, that because digital books are software, an author shouldn’t think of a book as merely data. The book is a program.

  • Third, that the way we make digital books better than their predecessors is by exploiting this programmability.

That’s what Pollen is for.

Not that you need to be a programmer to use Pollen. On the contrary, the Pollen language is markup-based, so you can write & edit text naturally. But when you want to automate repetitive tasks, add cross-references, or pull in data from other sources, you can access a full programming language from within the text.

That language is Racket. I chose Racket because while the idea for Pollen had been with me for several years, it simply wasn’t possible to build it with other languages. So if it’s unfamiliar to you, don’t panic. It was unfamiliar to me. Once you see what you can do with Pollen & Racket, you may be persuaded. I was.

Or, if you can find a better digital-publishing tool, use that. But I’m never going back to the way I used to work.

    1 Installation

    2 Quick tour

      2.1 Creating a source file

      2.2 Running a source file

      2.3 Naming, saving, and rendering a source file

      2.4 The project server

      2.5 Intermission

      2.6 Pollen as a preprocessor

      2.7 Markdown mode

      2.8 Markup mode

      2.9 Templates

      2.10 PS for Scribble users

      2.11 The end of the beginning

    3 Backstory

      3.1 Web development and its discontents

      3.2 The better idea: a programming model

      3.3 “Now you have two problems”

      3.4 Rethinking the solution for digital books

      3.5 Enter Racket

      3.6 What is Pollen?

    4 System overview

      4.1 The book is a program

      4.2 One language, multiple dialects

      4.3 Development environment

      4.4 A special data structure for HTML

      4.5 Preprocessor source files

      4.6 Templated source files

      4.7 Utility source files

      4.8 Pagetrees

      4.9 Build & deploy

    5 Using raco pollen

      5.1 Making sure raco pollen works

      5.2 raco pollen

      5.3 raco pollen help

      5.4 raco pollen start

      5.5 raco pollen render

      5.6 raco pollen clone

    6 File formats

      6.1 Source formats

        6.1.1 Command syntax using ◊

        6.1.2 Any command is valid

        6.1.3 Standard exports

        6.1.4 Custom exports

        6.1.5 The project-require.rkt file

        6.1.6 Preprocessor (.pp extension)

        6.1.7 Markdown (.pmd extension)

        6.1.8 Markup (.pm extension)

        6.1.9 Pagetree (.ptree extension)

      6.2 Utility formats

        6.2.1 Scribble (.scrbl extension)

        6.2.2 Null (.p extension)

    7 ◊ command overview

      7.1 The golden rule

      7.2 The lozenge glyph (◊)

      7.3 The two command modes: text mode & Racket mode

        7.3.1 The command name

          7.3.1.1 Invoking tag functions

          7.3.1.2 Invoking other functions

          7.3.1.3 Inserting the value of a variable

          7.3.1.4 Inserting a comment

        7.3.2 The Racket arguments

        7.3.3 The text argument

      7.4 Further reading

    8 Module reference

      8.1 Cache

      8.2 Decode

        8.2.1 Block

        8.2.2 Typography

      8.3 File

      8.4 Pagetree

        8.4.1 Navigation

        8.4.2 Utilities

      8.5 Render

      8.6 Template

      8.7 Tag

      8.8 Top

      8.9 World

    9 Acknowledgments

    10 License & source code

    Index

 
\ No newline at end of file diff --git a/doc/pollen/out0.sxref b/doc/pollen/out0.sxref new file mode 100644 index 0000000..d27775b Binary files /dev/null and b/doc/pollen/out0.sxref differ diff --git a/doc/pollen/out1.sxref b/doc/pollen/out1.sxref new file mode 100644 index 0000000..2a4be25 Binary files /dev/null and b/doc/pollen/out1.sxref differ diff --git a/doc/pollen/provides.sxref b/doc/pollen/provides.sxref new file mode 100644 index 0000000..28c8ce0 Binary files /dev/null and b/doc/pollen/provides.sxref differ diff --git a/doc/pollen/quick-tour.html b/doc/pollen/quick-tour.html new file mode 100644 index 0000000..b3d6cc6 --- /dev/null +++ b/doc/pollen/quick-tour.html @@ -0,0 +1,2 @@ + +2 Quick tour
6.0

2 Quick tour

2.1 Creating a source file

Assuming you’ve installed Racket & Pollen, launch DrRacket.

Open a new document. Change the top line to:

#lang pollen

The first line of every Pollen source file will start with #lang pollen.

2.2 Running a source file

Add a second line to your source file so it reads:

#lang pollen
Hello world

Click the Run button. In the interactions window, you’ll see the result:

Hello world

Not bad. I think Pollen just won the Hello World Tournament.

You can work with Pollen source files in any text editor. The key advantage of DrRacket is that you can preview the results by running the file.

Try editing your source file:

#lang pollen
Goodbye Stranger
Breakfast in America
Take the Long Way Home

You don’t have to use Supertramp song titles. Any text will do. When you click Run again, you’ll see whatever you typed:

Goodbye Stranger
Breakfast in America
Take the Long Way Home

We won’t do it a third time. You get the point — any plain text is valid within a Pollen source file, and gets printed as is. You never have to perform the incantations of typical programming languages:

print "Hello world"

document.write('Hello world');

printf("Hello world");

In Pollen, what you write is what you get.

2.3 Naming, saving, and rendering a source file

Save this file with the name hello.txt.pp in any convenient directory. The desktop is fine.

Open a terminal window and issue two commands:

> cd [directory containing your file]

> raco pollen render hello.txt.pp

After a moment, a new file will appear called hello.txt. Let’s see what’s in it:

> cat hello.txt

Goodbye Stranger

Breakfast in America

Take the Long Way Home

You’ve just learned three things:

  • Pollen commands in the terminal begin with raco pollen, followed by a specific command (in this case render) and sometimes an argument (in this case hello.txt.pp).

  • The render command takes the ouput from your source file — meaning, the result you previewed in DrRacket in the previous step — and saves it to another file.

  • The name of the output file is the same as the source file, minus the Pollen source extension. So hello.txt.pp becomes hello.txt.

Try editing the text in the hello.txt.pp source file and running raco pollen render hello.txt.pp again. The old hello.txt will be replaced with a new one showing your changes. And so you’ve learned a fourth thing:

  • Pollen works by rendering output files from source files. Output files can be overwritten. Therefore, you should only make edits to your source files.

2.4 The project server

You’ve just learned two ways to see the output of a Pollen source file — first, you ran it in DrRacket. Then, you rendered it to an output file.

Now here’s a third: the Pollen project server. Here’s how you start it. Return to your terminal window and issue two commands:

> cd [directory containing your hello.txt.pp file]

> raco pollen start

After a moment, you’ll see the startup message:

Welcome to Pollen 0.001 (Racket 6.0.0.5)

Project root is /path/to/your/directory

Project server is http://localhost:8080 (Ctrl-C to exit)

Project dashboard is http://localhost:8080/index.ptree

Ready to rock

Open a web browser and point it at http://localhost:8080/index.ptree. The top of the window will say Project root. Below that will be a listing of the files in the directory.

Among them will be hello.txt, with a greyed-out .pp extension. Click on it, and you’ll be taken to http://localhost:8080/hello.txt, where you’ll see:

Goodbye Stranger

Breakfast in America

Take the Long Way Home

That’s the boring part. Here’s the good part. Leave the project server running. Open your source file again in DrRacket and edit it as follows:

"hello.txt.pp"

#lang pollen
Mean Street
Panama
Hear About It Later

Go back to your web browser and reload http://localhost:8080/hello.txt. Now you’ll see this:

Mean Street

Panama

Hear About It Later

Notice what happened — the Pollen project server dynamically regenerated the output file (hello.txt) from the source file (hello.txt.pp) after you edited the source. If you like, try making some more changes to hello.txt.pp, and reloading the browser to see the updates in hello.txt.

2.5 Intermission

That covers input & output. Now let’s circle back and look at what else you can do with Pollen (beyond the epic achievement of displaying plain text in a web browser).

For the rest of this tutorial, I recommend keeping two windows on screen: a web-browser window pointed at your project server (the main URL is http://localhost:8080/index.ptree) and the DrRacket editing window.

2.6 Pollen as a preprocessor

A preprocessor is a tool for making systematic, automated changes to a source file before the main processing happens. A preprocessor can also be used to add programming logic to files that otherwise don’t support it.

For instance, HTML. In DrRacket, create a new file called margin.html.pp in your project directory:

"margin.html.pp"

#lang pollen
<body style="margin: 5em; border:1px solid black">
5em is the inset.
</body>

The “.pp” file extension — which you saw before, with hello.txt.pp — stands for “Pollen preprocessor.” You can use the Pollen preprocessor with any text-based file by inserting #lang pollen as the first line, and adding the .pp file extension.

But for now, go to your project dashboard and click on margin.html. You should see a black box containing the text “5em is the inset.”

Let’s suppose you want to change the inset to 30%. Without a preprocessor, you’d have to search & replace each value. But with a preprocessor, you can move the inset value into a variable, and update it from that one location. So first, introduce a variable called my-inset by using the define command:

"margin.html.pp"

#lang pollen
◊define[my-inset]{30%}
<body style="margin: 10em; border:1px solid black">
10em is the inset.
</body>

The ◊ character is called a lozenge. In Pollen, the lozenge is a special character that marks anything Pollen should interpret as a command (rather than plain text). The whole command ◊define[my-inset]{30%} means “create a variable called my-inset and give it the value 30%.”

Then put the variable into the HTML like so, this time using the ◊ character with the variable name in the two places the value appears:

"margin.html.pp"

#lang pollen
◊define[my-inset]{30%}
<body style="margin: ◊my-inset; border:1px solid black">
◊my-inset is the inset.
</body>

Now reload margin.html. You’ll see that the size of the margin has changed (because of the change to the style attribute) and so has the text of the HTML. If you like, try editing my-inset with different values and reloading the page. You can also try using define to create another variable (for instance, to change the color of the box border).

Still, this is the tiniest tip of the iceberg. The Pollen preprocessor gives you access to everything in the Racket programming language — including math functions, text manipulation, and so on.

2.7 Markdown mode

When used as a preprocessor, Pollen’s rule is that what you write is what you get. But if you’re targeting HTML, who wants to type out all those <tedious>tags</tedious>? You can make Pollen do the heavy lifting by using it as a source decoder.

For instance, Markdown mode. Markdown is a simplified notation system for HTML. You can use Pollen’s Markdown decoder by inserting #lang pollen as the first line, and adding the .pmd file extension.

Try it. In DrRacket, create a file with the following lines and save it as downtown.html.pmd:

"downtown.html.pmd"

#lang pollen
 
Pollen + Markdown
-----------------
 
+ You **wanted** it  you _got_ it.
 
+ [search for Racket](https://google.com/search?q=racket)

As before, go to the dashboard for the project server. This time, click the link for downtown.html. You’ll see something like this:

Pollen + Markdown

As usual, you’re welcome to edit downtown.html.pmd and then refresh the web browser to see the changes.

In Markdown mode, you can still embed Pollen commands within the source as you did in preprocessor mode. Just keep in mind that your commands need to produce valid Markdown (as opposed to raw HTML). For instance, use define to create a variable called metal, and insert it into the Markdown:

"downtown.html.pmd"

#lang pollen
◊define[metal]{Plutonium}
 
Pollen + ◊metal
--------
 
+ You **wanted** ◊metal  you _got_ it.
 
+ [search for ◊metal](https://google.com/search?q=◊metal)

Refresh downtown.html in the browser:

Pollen + Plutonium

Pollen is handling two tasks here: interpreting the commands in the source, and then converting the Markdown to HTML. But what if you wanted to use Pollen as a preprocessor that outputs a Markdown file? No problem — just change the source name from downtown.html.pmd to downtown.md.pp. Changing the extension from .pmd to .pp switches Pollen from Markdown mode back to preprocessor mode. And changing the base name from downtown.html to downtown.md updates the name of the output file.

2.8 Markup mode

If all you need to do is produce basic HTML, Markdown is great. But if you need to do semantic markup or other kinds of custom markup, it’s not flexible enough.

In that case, you can use Pollen markup mode. To use Pollen markup, insert #lang pollen as the first line of your source file, and add a .pm file extension.

Compared to Markdown mode, Pollen markup mode is wide open. Markdown mode gives you a limited set of formatting tools (i.e., the ones supported by Markdown). But in markup mode, you can use any tags you want. Markdown mode decodes the source in a fixed way (i.e., with the Markdown decoder). But markup mode lets you build any decoder you want.

Let’s convert our Markdown example into Pollen markup. Marking up content is simple: insert the lozenge character () followed by the name of the tag (◊tag), followed by the content of the tag in curly braces (◊tag{content}). In DrRacket, create a new file called uptown.html.pm as follows:

"uptown.html.pm"

#lang pollen
 
◊headline{Pollen markup}
 
◊items{
 
◊item{You ◊strong{wanted} it  you ◊em{got} it.}
 
◊item{◊link["https://google.com/search?q=racket"]{search for Racket}}}

Go to the project dashboard and click on uptown.html. You’ll see something like this:

Pollen markup You wanted it — you got it. https://google.com/search?q=racketsearch for Racket

That’s not right. What happened?

We marked up the source using a combination of standard HTML tags (strong, em) and nonstandard ones (headline, items, item, link). This is valid Pollen markup. (In fact, if you look at the generated source, you’ll see that they didn’t disappear.) But since we’re targeting HTML, we need to convert our custom tags into valid HTML tags.

For that, we’ll make a special file called project-require.rkt. This is a file in the standard Racket language that provides helper functions to decode the source. The definitions won’t make sense yet. But this is the quick tour, so all you need to do is copy, paste, and save:

"project-require.rkt"

#lang racket/base
(require pollen/tag)
(provide (all-defined-out))
(define headline (make-tag-function 'h2))
(define items (make-tag-function 'ul))
(define item (make-tag-function 'li 'p))
(define (link url text) `(a [[href ,url]] ,text))

Return to the project dashboard and click on uptown.html. Now you’ll get the right result:

Pollen markup

Markup mode takes a little more effort to set up. But it also allows you more flexibility. If you want to do semantic markup, or convert your source into multiple output formats, or handle complex page layouts — it’s the way to go.

2.9 Templates

The HTML pages we just made looked pretty dull. For the last stop on the quick tour, let’s fix that.

Pollen source files that are written in Markdown or markup mode (i.e., .pmd or .pm files) are rendered with a template. A template is not a standalone Pollen source file. It’s a file of the output type — e.g., CSS, HTML, XML — where you put the stuff that needs to be consistent between output files. The template also contains template variables that mark where values from the Pollen source file should be inserted.

When it needs a template, Pollen first looks for a file in the project directory named template.[output extension of source]. For uptown.html.pm, the output extension will be .html, thus Pollen will look for template.html.

So let’s create template.html. Make a new file that with the following lines and save it to the same directory as uptown.html.pm:

"template.html"

<html><head><meta charset="UTF-8"/></head>

<body style="background: #f6f6f6">

<div style="background: white; margin: 3em;

border:10px double gray; padding: 3em; font-size: 130%;">

This file is ◊here

<hr />

◊->html{◊doc}

</div></body></html>

This is a simple HTML file that should look familiar, except for the two template variables. The first, here, contains the name of the current source file. As before, the lozenge character marks it as a Pollen command rather than text, so you write it as ◊here. The other command, ◊->html{◊doc}, takes the content from the source file, which is contained in a variable called doc, and converts it to HTML with a Pollen function called ->html.

Go back to your web browser and reload uptown.html. (Or downtown.html — both will work.) The page will be rendered with the new template.html. As before, you can edit the template or the source and the project server will dynamically update the output file.

2.10 PS for Scribble users

Pollen can also be used as a dynamic preview server for Scribble files. From your terminal, do the following:

> cd [directory containing your Scribble files]

> raco pollen start

On the project dashboard, you’ll see your [filename].scrbl files listed as [filename].html. This may not represent the ultimate structure of your Scribble project — you may end up combining multiple Scribble source files into one HTML file, or making multiple HTML files from one Scribble source — but it’s handy for checking your work as you go.

2.11 The end of the beginning

Now you’ve seen the key features of Pollen. What do you think?

  • “So it’s like WordPress, but harder to use?” I was a happy WordPress user for several years. If you need a blog, it’s great. But the farther you get from blogs, the more it becomes like teaching an elephant to pirouette. And for those who like to solve problems with programming, PHP is, um, limited.

  • “What about pairing a Python template system and Python web server?” Good idea. I even tried it. But Python template systems don’t offer you Python — they offer you pidgin dialects that ain’t very Pythonic. Also, Python’s handing of markup-based data structures is cumbersome.

  • “Haven’t you heard of Jekyll?” Yes. If everything you need to write is expressible in Markdown, it’s great. If you need more than that, you’re stuck.

  • “Sounds a lot like LaTeX. Why not use that?” Also a good idea. LaTeX gets a lot of things right. But it wasn’t designed for web publishing.

  • “Eh, there are plenty of adequate options. Why should I learn a system written in Racket, which I’ve never used?” A salient objection. It’s also the question I asked myself before I committed to Racket. But publishing systems that are author- or designer-friendly tend to be programmer-hostile, and vice versa. Racket is the only language I found that could meet my requirements.

But don’t take my word for it. The rest of this documentation will show you the cool, useful, and sophisticated things you can do with Pollen. If there’s another tool that suits you better, great. Keep in mind that I didn’t make Pollen because I’m a programmer. I’m a writer who wants to make electronic books that are better than the ones we have now. And for that, I needed a better tool.

 
\ No newline at end of file diff --git a/doc/pollen/reader.html b/doc/pollen/reader.html new file mode 100644 index 0000000..5b1a6cd --- /dev/null +++ b/doc/pollen/reader.html @@ -0,0 +1,28 @@ + +7 â—Š command overview
6.0

7 ◊ command overview

7.1 The golden rule

Pollen uses a special character — the lozenge, which looks like this: ◊ — to mark commands within a Pollen source file. So when you put a ◊ in your source, whatever comes next will be treated as a command. If you don’t, it will just be interpreted as plain text.

7.2 The lozenge glyph (◊)

I chose the lozenge as the command marker because a) it appears in almost every font, b) it’s barely used in ordinary typesetting, c) it’s not used in any programming language that I know of, and d) its shape and color allow it to stand out easily in code without being distracting.

Here’s how you type it:

Mac: option + shift + V +
+Windows: +
+Ubuntu:

Still, if you don’t want to use the lozenge as your command marker, you can use something else. Set Pollen’s world:command-marker value to whatever character you want.

Scribble uses the @ sign as a delimiter. It’s not a bad choice if you only work with Racket files. But as you use Pollen to work on other kinds of text-based files that commonly contain @ signs — HTML pages especially — it gets cumbersome. So I changed it.

But don’t knock the lozenge till you try it.

7.3 The two command modes: text mode & Racket mode

Pollen commands can be entered in one of two modes: text mode or Racket mode. Both modes start with a lozenge ():

 command name [ Racket arguments ... ] { text argument }
 ( Racket expression )

Text-mode commands

A text-mode command has the three possible parts after the :

  • The command name appears immediately after the . Typically it’s a short word.

  • The Racket arguments appear between square brackets. Pollen is partly an interface to the Racket programming language. These arguments are entered using Racket conventions — e.g., a string of text needs to be put in quotes as a "string of text". If you like programming, you’ll end up using these frequently. If you don’t, you won’t.

  • The text argument appears between braces (aka curly brackets). You can put any ordinary text here. Unlike with the Racket arguments, you don’t put quotes around the text.

Each of the three parts is optional. You can also nest commands within each other. However:

  • You can never have spaces between the three parts.

  • Whatever parts you use must always appear in the order above.

Here are a few examples of correct text-mode commands:

#lang pollen
variable-name
tag{Text inside the tag.}
tag['attr: "value"]{Text inside the tag}
get-customer-id["Brennan Huff"]
tag{His ID is get-customer-id["Brennan Huff"].}

And some incorrect examples:

#lang pollen
tag {Text inside the tag.} ; space between first and second parts
tag[Text inside the tag] ; text argument needs to be within braces
tag{Text inside the tag}['attr: "value"] ; wrong order

The next section describes each of these parts in detail.

Racket-mode commands

If you’re familiar with Racket expressions, you can use the Racket-mode commands to embed them within Pollen source files. It’s simple: any Racket expression can become a Pollen command by adding to the front. So in Racket, this code:

#lang racket
(define song "Revolution")
(format "~a #~a" song (* 3 3))

Can be converted to Pollen like so:

#lang pollen
(define song "Revolution")
(format "~a #~a" song (* 3 3))

And in DrRacket, they produce the same output:

Revolution #9

Beyond that, there’s not much to say about Racket mode — any valid expression you can write in Racket will also be a valid Racket-mode Pollen command.

The relationship of text mode and Racket mode

Even if you don’t plan to write a lot of Racket-mode commands, you should be aware that under the hood, Pollen is converting all commands in text mode to Racket mode. So a text-mode command that looks like this:

◊headline[#:size 'enormous]{Man Bites Dog!}

Is actually being turned into a Racket-mode command like this:

(headline #:size 'enormous "Man Bites Dog!")

Thus a text-mode command is just an alternate way of writing a Racket-mode command. (More broadly, all of Pollen is just an alternate way of using Racket.)

The corollary is that you can always write Pollen commands using whichever mode is more convenient or readable. For instance, the earlier example, written in the Racket mode:

#lang pollen
(define song "Revolution")
(format "~a #~a" song (* 3 3))

Can be rewritten using text mode:

#lang pollen
define[song]{Revolution}
format["~a #~a" song (* 3 3)]

And it will work the same way.

7.3.1 The command name

In Pollen, you’ll typically use the command name for one of four purposes:

  • To invoke a tag function.

  • To invoke another function.

  • To insert the value of a variable.

  • To insert a comment.

7.3.1.1 Invoking tag functions

By default, Pollen treats every command name as a tag function. As the name implies, a tag function creates a tagged X-expression with the command name as the tag, and the text argument as the content.

#lang pollen
strong{Fancy Sauce, $1}

'(strong "Fancy Sauce, $1")

To streamline markup, Pollen doesn’t restrict you to a certain set of tags, nor does it make you define your tag functions ahead of time. Just type a tag, and you can start using it.

#lang pollen
utterlyridiculoustagname{Oh really?}
'(utterlyridiculoustagname "Oh really?")

The one restriction is that you can’t invent names for tag functions that are already being used for other commands. For instance, map is a name permanently reserved by the Racket function map. It’s also a rarely-used HTML tag. But gosh, you really want to use it. Problem is, if you invoke it directly, Pollen will think you mean the other map:

#lang pollen
map{Fancy Sauce, $1}

map: arity mismatch;
+the expected number of arguments does not match the given number
+  given: 1
+  arguments...:
+    "Fancy Sauce, $1"

What to do? Read on.

7.3.1.2 Invoking other functions

Though every command name starts out as a tag function, it doesn’t necessarily end there. You have two options for invoking other functions: defining your own , or invoking others from Racket.

Defining your own functions

Use the define command to create your own function for a command name. After that, when you use the command name, you’ll get the new behavior. For instance, recall this example showing the default tag-function behavior:

#lang pollen
strong{Fancy Sauce, $1}

'(strong "Fancy Sauce, $1")

We can define strong to do something else, like add to the text:

#lang pollen
(define (strong text) `(strong ,(format "Hey! Listen up! ~a" text)))
strong{Fancy Sauce, $1}

'(strong "Hey! Listen up! Fancy Sauce, $1")

The replacement function has to accept any arguments that might get passed along, but it doesn’t have to do anything with them. For instance, this function definition won’t work because strong is going to get a text argument that it’s not defined to handle:

#lang pollen
(define (strong) '(fib "1 1 2 3 5 8 13 ..."))
strong{Fancy Sauce, $1}

strong: arity mismatch;
+the expected number of arguments does not match the given number
+  expected: 0
+  given: 1
+  arguments...:
+    "Fancy Sauce, $1"

Whereas in this version, strong accepts an argument called text, but then ignores it:

#lang pollen
(define (strong text) '(fib "1 1 2 3 5 8 13 ..."))
strong{Fancy Sauce, $1}

'(fib "1 1 2 3 5 8 13 ...")

You can attach any behavior to a command name. As your project evolves, you can also update the behavior of a command name. In that way, Pollen commands become a set of hooks to which you can attach more elaborate processing.

Using Racket functions

You aren’t limited to functions you define. Any function from Racket, or any Racket library, can be invoked directly by using it as a command name. Here’s the function range, which creates a list of numbers:

#lang pollen
range[1 20]

'(range 1 20)

Hold on — that’s not what we want. Where’s the list of numbers? The problem here is that we didn’t explicitly import the racket/list library, which contains the definition for range. (If you need to find out what library contains a certain function, the Racket documentation will tell you.) Without racket/list, Pollen just thinks we’re trying to use range as a tag function (and if we had been, then '(range 1 20) would’ve been the right result).

We fix this by using the require command to bring in the racket/list library, which contains the range we want:

#lang pollen
(require racket/list)
range[1 20]

'(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)

Of course, you can also invoke Racket functions indirectly, by attaching them to functions you define for command names:

#lang pollen
(require racket/list)
(define (rick start finish) (range start finish))
rick[1 20]

'(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)

Let’s return to the problem that surfaced in the last section — the fact that some command names can’t be used as tag functions because they’re already being used for other things. You can work around this by defining your own tag function with a non-conflicting name.

For instance, suppose we want to use map as a tag even though Racket is using it for its own function called map. First, we invent a command name that doesn’t conflict. Let’s call it my-map. As you learned above, Pollen will treat a new command name as a tag function by default:

#lang pollen
my-map{How I would love this to be a map.}

'(my-map "How I would love this to be a map.")

But my-map is not the tag we want. We need to define my-map to be a tag function for map. We can do this with the Pollen helper make-tag-function. That function lives in pollen/tag, so we require that too:

#lang pollen
(require pollen/tag)
(define my-map (make-tag-function 'map))
my-map{How I would love this to be a map.}

'(map "How I would love this to be a map.")

Problem solved.

7.3.1.3 Inserting the value of a variable

A Pollen command name usually refers to a function, but it can also refer to a variable, which is a data value. Once you define the variable, you can insert it into your source by using the ◊ notation without any other arguments:

#lang pollen
(define foo "bar")
The value of foo is foo

The value of foo is bar

Be careful — if you include arguments, even blank ones, Pollen will treat the command name as a function. This won’t work, because a variable is not a function:

To understand what happens here, recall the relationship between Pollen’s command modes. The text-mode command ◊foo[] becomes the Racket-mode command (foo), which after variable substitution becomes ("bar"). If you try to evaluate ("bar") — e.g., in DrRacket — you’ll get the same error.

#lang pollen
(define foo "bar")
The value of foo is foo[]

application: not a procedure;
+expected a procedure that can be applied to arguments
+  given: "bar"
+  arguments...: [none]

The reason we can simply drop ◊foo into the text argument of another Pollen command is that the variable foo holds a string (i.e., a text value). When appropriate, Pollen will convert a variable to a string in a sensible way. For instance, numbers are easily converted:

#lang pollen
(define zam 42)
The value of zam is zam

The value of zam is 42

If the variable holds a container datatype (like a list, hash, or vector), Pollen will produce the Racket text representation of the item. Here, zam is a list of integers:

#lang pollen
(define zam (list 1 2 3))
The value of zam is zam

The value of zam is '(1 2 3)

This feature is included for your convenience as an author. But in general, your readers won’t want to see the Racket representation of a container. So in these cases, you should convert to a string manually in some sensible way. Here, the integers in the list are converted to strings, which are then combined using string-join from the racket/string library:

#lang pollen
(require racket/string)
(define zam (list 1 2 3))
The value of zam is string-join[(map number->string zam)]{ and }

The value of zam is 1 and 2 and 3

Pollen will still produce an error if you try to convert an esoteric value to a string. Here, zam is the addition function (+):

#lang pollen
(define zam +)
The value of zam is zam

Pollen decoder: can’t convert #<procedure:+> to string

One special case to know about. In the examples above, there’s a word space between the variable and the other text. But suppose you need to insert a variable into text so that there’s no space in between. The simple ◊ notation won’t work, because it won’t be clear where the variable name ends and the text begins.

For instance, suppose we want to use a variable edge next to the string px:

#lang pollen
(define edge 100)
p { margin-left: edgepx; }

Pollen decoder: can’t convert #<procedure:...t/pollen/tag.rkt:6:2> to string

The example fails because Pollen reads the whole string after the as the single variable name edgepx. Since edgepx isn’t defined, it’s treated as a tag function, and since Pollen can’t convert a function to a string, we get an error.

In these situations, surround the variable name with vertical bars ◊|like so| to explicitly indicate where the variable name ends. The bars are not treated as part of the name, nor are they included in the result. Once we do that, we get what we intended:

#lang pollen
(define edge 100)
p { margin-left: ◊|edge|px; }

p { margin-left: 100px; }

If you use this notation when you don’t need to, nothing bad will happen. The vertical bars are always ignored.

#lang pollen
(define edge 100)
The value of edge is ◊|edge| pixels}

The value of edge is 100 pixels

7.3.1.4 Inserting a comment

Two options.

To comment out the rest of a single line, use a lozenge followed by a semicolon ◊;.

#lang pollen
span{This is not a comment}
span{Nor is this} ;span{But this is}

'(span "This is not a comment")
+'(span "Nor is this")

To comment out a multiline block, use the lozenge–semicolon signal ◊; with curly braces, ◊;{like so}.

#lang pollen
;{
◊span{This is not a comment}
◊span{Nor is this} ;span{But this is}
}
Actually, it's all a comment now

Actually, it's all a comment now

7.3.2 The Racket arguments

The middle part of a text-mode Pollen command contains the Racket arguments [between square brackets.] Most often, you’ll see these used to pass extra information to commands that operate on text.

For instance, tag functions. Recall from before that any not-yet-defined command name in Pollen is treated as a tag function:

#lang pollen
title{The Beginning of the End}

'(title "The Beginning of the End")

But what if you wanted to add attributes to this tag, so that it comes out like this?

'(title ((class "red")(id "first")) "The Beginning of the End")

You can do it with Racket arguments.

Here’s the hard way. You can type out your list of attributes in Racket format and drop them into the brackets as a single argument:

#lang pollen
title['((class "red")(id "first"))]{The Beginning of the End}

'(title ((class "red") (id "first")) "The Beginning of the End")

But that’s a lot of parentheses to think about. So here’s the easy way. Anytime you use a tag function, there’s a shortcut for inserting attributes. You can enter them as a series of symbol / string pairs between the Racket-argument brackets. The only caveat is that the symbols have to begin with a quote mark ' and end with a colon :. So taken together, they look like this:

#lang pollen
title['class: "red" 'id: "first"]{The Beginning of the End}

'(title ((class "red") (id "first")) "The Beginning of the End")

Racket arguments can be any valid Racket expressions. For instance, this will also work:

#lang pollen
title['class: (format "~a" (* 6 7)) 'id: "first"]{The Beginning of the End}

'(title ((class "42") (id "first")) "The Beginning of the End")

Since Pollen commands are really just Racket arguments underneath, you can use those too. Here, we’ll define a variable called name and use it in the Racket arguments of title:

#lang pollen
(define name "Brennan")
title['class: "red" 'id: name]{The Beginning of the End}

'(title ((class "read") (id "Brennan")) "The Beginning of the End")

You can also use this area for keyword arguments. Keyword arguments can be used to provide options for a particular Pollen command, to avoid redundancy. Suppose that instead of using the h1 ... h6 tags, you want to consolidate them into one command called heading and select the level separately. You can do this with a keyword, in this case #:level, which is passed as a Racket argument:

#lang pollen
(define (heading #:level which text)
   `(,(string->symbol (format "h~a" which)) ,text))
 
heading[#:level 1]{Major league}
heading[#:level 2]{Minor league}
heading[#:level 6]{Trivial league}

'(h1 "Major league")
+'(h2 "Minor league")
+'(h6 "Trivial league")

7.3.3 The text argument

The third part of a text-mode Pollen command is the text argument. The text argument {appears between curly braces}. It can contain any text you want. The text argument can also contain other Pollen commands with their own text arguments. And they can contain other Pollen commands ... and so on, all the way down.

#lang pollen
div{Do it again. div{And again. div{And yet again.}}}

'(div "Do it again. " (div "And again. " (div "And yet again.")))

Three small details to know about the text argument.

First, the only character that needs special handling in a text argument is the lozenge . A lozenge ordinarily marks a new command. So if you want an actual lozenge to appear in the text, you have to escape it by typing ◊"◊".

#lang pollen
definition{This is the lozenge: "◊"}

'(definition "This is the lozenge: ◊")

Second, the whitespace-trimming policy. Here’s the short version: if there’s a carriage return at either end of the text argument, it is trimmed, and whitespace at the end of each line is selectively trimmed in an intelligent way. So this text argument, with carriage returns on the ends:

#lang pollen
div{
Roomy!
 
I agree.
}

'(div "Roomy!" "\n" "\n" "I agree.")

Yields the same result as this one:

#lang pollen
div{Roomy!
 
I agree.}

'(div "Roomy!" "\n" "\n" "I agree.")

For the long version, please see [future link: Spaces, Newlines, and Indentation].

Third, within a multiline text argument, newline characters become individual strings that are not merged with adjacent text. So what you end up with is a list of strings, not a single string. That’s why in the last example, we got this:

'(div "Roomy!" "\n" "\n" "I agree.")

Instead of this:

'(div "Roomy!\n\nI agree.")

Under most circumstances, these two tagged X-expressions will behave the same way. The biggest exception is with functions. A function that operates on multiline text arguments needs to be able to handle an indefinite number of strings. For instance, this jejune function only accepts a single argument. It will work with a single-line text argument, because that produces a single string:

#lang pollen
(define (jejune text)
   `(jejune ,text))
jejune{Irrational confidence}

'(jejune "Irrational confidence")

But watch what happens with a multiline text argument:

#lang pollen
(define (jejune text)
   `(jejune ,text))
jejune{Deeply
        chastened}

jejune: arity mismatch;
+the expected number of arguments does not match the given number
+  expected: 1
+  given: 3
+  arguments...:
+   "Deeply"
+   "\n"
+   "chastened"

The answer is to use a rest argument in the function, which takes the “rest” of the arguments — however many there may be — and combines them into a single list. If we rewrite jejune with a rest argument, we can fix the problem:

#lang pollen
(define (jejune . texts)
   `(jejune ,@texts))
jejune{Deeply
        chastened}

'(jejune "Deeply" "\n" "chastened")

7.4 Further reading

The Pollen language is a variant of Racket’s own text-processing language, called Scribble. So many things that are true about Scribble are also true about Pollen. For the sake of clarity & brevity, I’ve omitted them from this summary. But if you want the full story, see @ Syntax in the Scribble documentation.

 
\ No newline at end of file diff --git a/doc/pollen/stamp.sxref b/doc/pollen/stamp.sxref new file mode 100644 index 0000000..006fdf0 --- /dev/null +++ b/doc/pollen/stamp.sxref @@ -0,0 +1 @@ +("27d89cec2f11d8a355d8c8113a4acf927313097a8e33dc9dc0336ad0e7b0ba6ed869604e84ae885e" "0cd6e2823df3d8442edf6389aaccad89ca957d3c7ec958fa14cc844c9ea0e7c420bd77ee53a2e982" "9b27b710bee743bf46119a21b53cc8f4221c65f3") \ No newline at end of file diff --git a/doc/pollen/synced.rktd b/doc/pollen/synced.rktd new file mode 100644 index 0000000..e69de29 diff --git a/doc/racket.css b/doc/racket.css index b44fef5..40a949e 100644 --- a/doc/racket.css +++ b/doc/racket.css @@ -144,6 +144,9 @@ .prototype td { vertical-align: text-top; } +.longprototype td { + vertical-align: bottom; +} .RktBlk { white-space: inherit; @@ -240,10 +243,3 @@ top: 0px; z-index: 1; } - -/* ---------------------------------------- */ -/* History */ - -.SHistory { - font-size: 82%; -} diff --git a/doc/scribble-style.css b/doc/scribble-style.css new file mode 100644 index 0000000..e69de29