/racket-5-0-2-bin-i386-osx-mac-dmg/collects/scribblings/scribble/decode.scrbl

http://github.com/smorin/f4f.arc · Racket · 213 lines · 138 code · 75 blank · 0 comment · 5 complexity · 66f9b596ee2e7e213b75d93aab45c491 MD5 · raw file

  1. #lang scribble/doc
  2. @(require scribble/manual
  3. "utils.ss")
  4. @title[#:tag "decode"]{Decoding Text}
  5. @defmodule[scribble/decode]{The @racketmodname[scribble/decode]
  6. library helps you write document content in a natural way---more like
  7. plain text, except for @litchar["@"] escapes. Roughly, it processes a
  8. stream of strings to produces instances of the
  9. @racketmodname[scribble/struct] datatypes (see @secref["struct"]).}
  10. At the @tech{flow} level, decoding recognizes a blank line as a
  11. @tech{paragraph} separator. Blocks and paragraphs without blank lines
  12. in between are collected into a @tech{compound paragraph}.
  13. At the @tech{content} level, decoding makes just a few
  14. special text conversions:
  15. @itemize[
  16. @item{@litchar{---}: converted to @racket['mdash], which the HTML render
  17. outputs as an en-dash surrounded by space (so don't put spaces around
  18. @litchar{---} in a document)}
  19. @item{@litchar{--}: converted to @racket['ndash]}
  20. @item{@litchar{``}: converted to @racket['ldquo], which is fancy open quotes: ``}
  21. @item{@litchar{''}: converted to @racket['rdquo], which is fancy closing quotes: ''}
  22. @item{@litchar{'}: converted to @racket['rsquo], which is a fancy apostrophe: '}
  23. ]
  24. Some functions @deftech{decode} a sequence of @racket[_pre-flow] or
  25. @racket[_pre-content] arguments using @racket[decode-flow] or
  26. @racket[decode-content], respectively. For example, the @racket[bold]
  27. function accepts any number of @racket[_pre-content] arguments, so
  28. that in
  29. @verbatim[#:indent 2]|{@bold{``apple''}}|
  30. the @litchar{``apple''} argument is decoded to use fancy quotes, and
  31. then it is bolded.
  32. @defproc[(pre-content? [v any/c]) boolean?]{
  33. Returns @racket[#t] if @racket[v] is a @deftech{pre-content} value: a
  34. string or other non-list @racket[content], or a @racket[splice]
  35. containing a list of @tech{pre-content} values; otherwise returns
  36. @racket[#f].
  37. Pre-content is decoded into @tech{content} by functions like
  38. @racket[decode-content] and @racket[decode-paragraph].}
  39. @defproc[(pre-flow? [v any/c]) boolean?]{
  40. Returns @racket[#t] if @racket[v] is a @deftech{pre-flow} value: a
  41. string or other non-list @racket[content], a @racket[block],
  42. @|void-const|, or a @racket[splice] containing a list of
  43. @tech{pre-flow} values; otherwise returns @racket[#f].
  44. Pre-flow is decoded into a @tech{flow} (i.e., a list of @tech{blocks})
  45. by functions like @racket[decode-flow].}
  46. @defproc[(pre-part? [v any/c]) boolean?]{
  47. Returns @racket[#t] if @racket[v] is a @deftech{pre-part} value: a
  48. string or other non-list @tech{content}, a @tech{block}, a
  49. @racket[part], a @racket[title-decl], a @racket[part-start], a
  50. @racket[part-index-decl], a @racket[part-collect-decl], a
  51. @racket[part-tag-decl], @|void-const|, or a @racket[splice] containing
  52. a list of @tech{pre-part} values; otherwise returns @racket[#f].
  53. A pre-part sequence is decoded into a @racket[part] by functions like
  54. @racket[decode] and @racket[decode-part].}
  55. @defproc[(decode [lst (listof pre-part?)]) part?]{
  56. Decodes a document, producing a part. In @racket[lst], instances of
  57. @racket[splice] are inlined into the list. An instance of
  58. @racket[title-decl] supplies the title for the part, plus tag, style
  59. and version information. Instances of @racket[part-index-decl] (that
  60. precede any sub-part) add index entries that point to the
  61. section. Instances of @racket[part-collect-decl] add elements to the
  62. part that are used only during the @techlink{collect pass}. Instances
  63. of @racket[part-tag-decl] add hyperlink tags to the section
  64. title. Instances of @racket[part-start] at level 0 trigger sub-part
  65. parsing. Instances of @racket[section] trigger are used as-is as
  66. subsections, and instances of @racket[paragraph] and other
  67. flow-element datatypes are used as-is in the enclosing flow.}
  68. @defproc[(decode-part [lst (listof pre-part?)]
  69. [tags (listof string?)]
  70. [title (or/c #f list?)]
  71. [depth exact-nonnegative-integer?])
  72. part?]{
  73. Like @racket[decode], but given a list of tag string for the part, a
  74. title (if @racket[#f], then a @racket[title-decl] instance is used if
  75. found), and a depth for @racket[part-start]s to trigger sub-part
  76. parsing.
  77. }
  78. @defproc[(decode-flow [lst (listof pre-flow?)]) flow?]{
  79. Decodes a flow. A sequence of two or more newlines separated only by
  80. whitespace counts is parsed as a paragraph separator. In @racket[lst],
  81. instances of @racket[splice] are inlined into the list. Instances of
  82. @racket[paragraph] and other flow-element datatypes are used as-is in
  83. the enclosing flow.
  84. }
  85. @defproc[(decode-compound-paragraph [lst (listof pre-flow?)]) block?]{
  86. Decodes a compound paragraph. If the compound paragraph contains a
  87. single block, the block is returned without a
  88. @racket[compound-paragraph] wrapper.
  89. }
  90. @defproc[(decode-paragraph [lst (listof pre-content?)]) paragraph?]{
  91. Decodes a paragraph.
  92. }
  93. @defproc[(decode-content [lst (listof pre-content?)]) list?]{
  94. Decodes @tech{content}.
  95. }
  96. @defproc[(decode-elements [lst (listof pre-content?)]) list?]{
  97. An alias for @racket[decode-content].
  98. }
  99. @defproc[(decode-string [s string?]) (listof content?)]{
  100. Decodes a single string to produce @tech{content}.
  101. }
  102. @defproc[(whitespace? [s string?]) boolean?]{
  103. Returns @racket[#t] if @racket[s] contains only whitespace, @racket[#f]
  104. otherwise.
  105. }
  106. @defstruct[title-decl ([tag-prefix (or/c #f string?)]
  107. [tags (listof string?)]
  108. [version (or/c string? #f)]
  109. [style any/c]
  110. [content content?])]{
  111. See @racket[decode] and @racket[decode-part]. The @racket[tag-prefix]
  112. and @racket[style] fields are propagated to the resulting
  113. @racket[part].
  114. }
  115. @defstruct[part-start ([depth integer?]
  116. [tag-prefix (or/c #f string?)]
  117. [tags (listof string?)]
  118. [style any/c]
  119. [title content?])]{
  120. Like @racket[title-decl], but for a sub-part. See @racket[decode] and
  121. @racket[decode-part].
  122. }
  123. @defstruct[part-index-decl ([plain-seq (listof string?)]
  124. [entry-seq list?])]{
  125. See @racket[decode]. The two fields are as for @racket[index-element].
  126. }
  127. @defstruct[part-collect-decl ([element element?])]{
  128. See @racket[decode].
  129. }
  130. @defstruct[part-tag-decl ([tag tag?])]{
  131. See @racket[decode].
  132. }
  133. @defstruct[splice ([run list?])]{
  134. See @racket[decode], @racket[decode-part], and @racket[decode-flow].
  135. }
  136. @defproc[(clean-up-index-string [str string?]) string?]{
  137. Trims leading and trailing whitespace, and converts non-empty
  138. sequences of whitespace to a single space character.}