mirror of
https://github.com/boostorg/build.git
synced 2026-02-13 12:22:17 +00:00
Implement the HTML output type.
[SVN r18772]
This commit is contained in:
@@ -30,8 +30,27 @@ rule output (
|
||||
)
|
||||
{
|
||||
type ?= plain ;
|
||||
output-target = $(target) ;
|
||||
output-type = $(type) ;
|
||||
if $(output-target) != $(target)
|
||||
{
|
||||
output-target = $(target) ;
|
||||
output-type = $(type) ;
|
||||
if $(output-type) = html
|
||||
{
|
||||
text
|
||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"
|
||||
"<html>"
|
||||
"<head>"
|
||||
"</head>"
|
||||
"<body link=\"#0000ff\" vlink=\"#800080\">"
|
||||
: true
|
||||
: prefix ;
|
||||
text
|
||||
"</body>"
|
||||
"</html>"
|
||||
:
|
||||
: suffix ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Generate a section with a description. The type of output can be
|
||||
@@ -48,53 +67,94 @@ rule section (
|
||||
{
|
||||
lines [ split-at-words $(name): ] ;
|
||||
lines ;
|
||||
local pre = ;
|
||||
while $(description)
|
||||
}
|
||||
else if $(output-type) = html
|
||||
{
|
||||
name = [ escape-html $(name) ] ;
|
||||
text <h3>$(name)</h3> <p> ;
|
||||
}
|
||||
local pre = ;
|
||||
while $(description)
|
||||
{
|
||||
local paragraph = ;
|
||||
while $(description) && $(description[1]) = "" { description = $(description[2-]) ; }
|
||||
if $(pre)
|
||||
{
|
||||
local paragraph = ;
|
||||
while $(description) && $(description[1]) = "" { description = $(description[2-]) ; }
|
||||
if $(pre)
|
||||
pre = ;
|
||||
while $(description) && ( $(description[1]) = "" || [ MATCH "^([ ])" : $(description[1]) ] )
|
||||
{ paragraph += $(description[1]) ; description = $(description[2-]) ; }
|
||||
if $(output-type) = plain
|
||||
{
|
||||
pre = ;
|
||||
while $(description) && ( $(description[1]) = "" || [ MATCH "^([ ])" : $(description[1]) ] )
|
||||
{ paragraph += $(description[1]) ; description = $(description[2-]) ; }
|
||||
lines $(paragraph) : " " " " ;
|
||||
}
|
||||
else
|
||||
else if $(output-type) = html
|
||||
{
|
||||
while $(description) && $(description[1]) != ""
|
||||
{ paragraph += $(description[1]) ; description = $(description[2-]) ; }
|
||||
if $(paragraph[1]) = :: && ! $(paragraph[2])
|
||||
{
|
||||
pre = yes ;
|
||||
}
|
||||
if $(paragraph[1]) = ::
|
||||
text <blockquote> ;
|
||||
lines $(paragraph) ;
|
||||
text </blockquote> ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while $(description) && $(description[1]) != ""
|
||||
{ paragraph += $(description[1]) ; description = $(description[2-]) ; }
|
||||
if $(paragraph[1]) = :: && ! $(paragraph[2])
|
||||
{
|
||||
pre = yes ;
|
||||
}
|
||||
if $(paragraph[1]) = ::
|
||||
{
|
||||
if $(output-type) = plain
|
||||
{
|
||||
lines $(paragraph[2-]) : " " " " ;
|
||||
lines ;
|
||||
}
|
||||
else
|
||||
else if $(output-type) = html
|
||||
{
|
||||
local p = [ MATCH "(.*)(::)$" : $(paragraph[-1]) ] ;
|
||||
local pws = [ MATCH "([ ]*)$" : $(p[1]) ] ;
|
||||
p = [ MATCH "(.*)($(pws))($(p[2]))$" : $(paragraph[-1]) ] ;
|
||||
if $(p[3]) = ::
|
||||
text <blockquote> ;
|
||||
lines $(paragraph[2-]) ;
|
||||
text </blockquote> ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
local p = [ MATCH "(.*)(::)$" : $(paragraph[-1]) ] ;
|
||||
local pws = [ MATCH "([ ]*)$" : $(p[1]) ] ;
|
||||
p = [ MATCH "(.*)($(pws))($(p[2]))$" : $(paragraph[-1]) ] ;
|
||||
if $(p[3]) = ::
|
||||
{
|
||||
pre = yes ;
|
||||
if ! $(p[2]) || $(p[2]) = "" { paragraph = $(paragraph[1--2]) $(p[1]): ; }
|
||||
else { paragraph = $(paragraph[1--2]) $(p[1]) ; }
|
||||
if $(output-type) = plain
|
||||
{
|
||||
pre = yes ;
|
||||
if ! $(p[2]) || $(p[2]) = "" { paragraph = $(paragraph[1--2]) $(p[1]): ; }
|
||||
else { paragraph = $(paragraph[1--2]) $(p[1]) ; }
|
||||
lines [ split-at-words " " $(paragraph) ] : " " " " ;
|
||||
lines ;
|
||||
}
|
||||
else
|
||||
else if $(output-type) = html
|
||||
{
|
||||
text </p> <p> [ escape-html $(paragraph) ] ;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if $(output-type) = plain
|
||||
{
|
||||
lines [ split-at-words " " $(paragraph) ] : " " " " ;
|
||||
lines ;
|
||||
}
|
||||
else if $(output-type) = html
|
||||
{
|
||||
text </p> <p> [ escape-html $(paragraph) ] ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if $(output-type) = html
|
||||
{
|
||||
text </p> ;
|
||||
}
|
||||
}
|
||||
|
||||
# Generate the start of a list of items. The type of output can be
|
||||
@@ -107,6 +167,10 @@ rule list-start ( )
|
||||
if $(output-type) = plain
|
||||
{
|
||||
}
|
||||
else if $(output-type) = html
|
||||
{
|
||||
text <ul> ;
|
||||
}
|
||||
}
|
||||
|
||||
# Generate an item in a list. The type of output can be
|
||||
@@ -122,6 +186,10 @@ rule list-item (
|
||||
{
|
||||
lines [ split-at-words "*" $(item) ] : " " ;
|
||||
}
|
||||
else if $(output-type) = html
|
||||
{
|
||||
text <li> [ escape-html $(item) ] </li> ;
|
||||
}
|
||||
}
|
||||
|
||||
# Generate the end of a list of items. The type of output can be
|
||||
@@ -135,6 +203,10 @@ rule list-end ( )
|
||||
{
|
||||
lines ;
|
||||
}
|
||||
else if $(output-type) = html
|
||||
{
|
||||
text </ul> ;
|
||||
}
|
||||
}
|
||||
|
||||
# Split the given text into separate lines, word-wrapping to a margin.
|
||||
@@ -211,7 +283,8 @@ rule lines (
|
||||
else if $(c) = " " { c = ; }
|
||||
indent = $(indent)$(c) ;
|
||||
}
|
||||
text $(text[1])<br> $(indent)$(text[2-])<br> ;
|
||||
local html-text = [ escape-html $(text) : ] ;
|
||||
text $(html-text[1])<br> $(indent)$(html-text[2-])<br> ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +293,7 @@ rule lines (
|
||||
rule text (
|
||||
strings * # The strings of text to output.
|
||||
: overwrite ? # true to overwrite the output (if it is a file)
|
||||
: prefix-or-suffix ? # Indication of special prefix or suffix text.
|
||||
)
|
||||
{
|
||||
if $(output-target) = console
|
||||
@@ -240,21 +314,28 @@ rule text (
|
||||
else if $(output-target)
|
||||
{
|
||||
$(output-target).line ?= 0 ;
|
||||
DEPENDS $(output-target) : $(output-target:G=body) ;
|
||||
ALWAYS $(output-target:G=body) ;
|
||||
NOTFILE $(output-target:G=body) ;
|
||||
while $(strings)
|
||||
{
|
||||
local line-v = $(output-target).line.$($(output-target).line) ;
|
||||
local echo-string = [ escape $(strings[1]) ] ;
|
||||
$(line-v) on $(output-target) = $(echo-string) ;
|
||||
NOCARE $(line-v) ;
|
||||
local target = $(output-target:G=body) ;
|
||||
if $(prefix-or-suffix) = suffix
|
||||
{
|
||||
target = $(output-target) ;
|
||||
}
|
||||
$(line-v) on $(target) = $(echo-string) ;
|
||||
NOTFILE $(line-v) ;
|
||||
if $(overwrite) = "true"
|
||||
{
|
||||
overwrite = false ;
|
||||
text-overwrite-action $(output-target) : $(line-v) ;
|
||||
text-overwrite-action $(target) : $(line-v) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
text-action $(output-target) : $(line-v) ;
|
||||
{
|
||||
text-action $(target) : $(line-v) ;
|
||||
}
|
||||
strings = $(strings[2-]) ;
|
||||
$(output-target).line = [ numbers.increment $($(output-target).line) ] ;
|
||||
@@ -269,18 +350,45 @@ rule wrapped-text ( text + )
|
||||
text $(lines) ;
|
||||
}
|
||||
|
||||
# Escapes text into html/xml printable equivalents.
|
||||
# Does not know about tags and therefore tags fed into
|
||||
# this will also be escaped. Currently escapes space, "<", ">", and "&".
|
||||
#
|
||||
rule escape-html (
|
||||
text + # The text to escape.
|
||||
: space ? # What to replace spaces with, defaults to " ".
|
||||
)
|
||||
{
|
||||
local html-text = ;
|
||||
while $(text)
|
||||
{
|
||||
local html = $(text[1]) ;
|
||||
text = $(text[2-]) ;
|
||||
html = [ regex.replace $(html) "&" "&" ] ;
|
||||
html = [ regex.replace $(html) "<" "<" ] ;
|
||||
html = [ regex.replace $(html) ">" ">" ] ;
|
||||
if $(space)
|
||||
{
|
||||
html = [ regex.replace $(html) " " "$(space)" ] ;
|
||||
}
|
||||
html-text += $(html) ;
|
||||
}
|
||||
return $(html-text) ;
|
||||
}
|
||||
|
||||
|
||||
# Append single line to target file.
|
||||
#
|
||||
actions quietly text-action
|
||||
{
|
||||
echo $($(>)) >> $(<)
|
||||
echo $($(>)) >> $(<:G=)
|
||||
}
|
||||
|
||||
# Writes a single line to target file (overwriting or creating the
|
||||
# file as necessary)
|
||||
actions quietly text-overwrite-action {
|
||||
echo $($(>)) > $(<)
|
||||
actions quietly text-overwrite-action
|
||||
{
|
||||
echo $($(>)) > $(<:G=)
|
||||
}
|
||||
|
||||
if [ modules.peek : NT ]
|
||||
@@ -307,4 +415,6 @@ local rule __test__ ( )
|
||||
assert.result "one two" three : split-at-words one two three : 8 ;
|
||||
assert.result "one two" three : split-at-words one two three : 9 ;
|
||||
assert.result "one two three" : split-at-words one two three ;
|
||||
assert.result "one two three" "&<>" :
|
||||
escape-html "one two three" "&<>" ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user