can override utf-8 with either 'charset=<cs>' or per-module with @charset <cs>

This commit is contained in:
steve donovan 2013-03-27 15:50:37 +02:00
parent d176dedcfc
commit 158aa9ff14
4 changed files with 11 additions and 4 deletions

View File

@ -121,7 +121,7 @@ local file_types = {
------- ldoc external API ------------
-- the ldoc table represents the API available in `config.ld`.
local ldoc = {}
local ldoc = { charset = 'UTF-8' }
local add_language_extension
local function override (field)
@ -183,7 +183,7 @@ end
local ldoc_contents = {
'alias','add_language_extension','new_type','add_section', 'tparam_alias',
'file','project','title','package','format','output','dir','ext', 'topics',
'one','style','template','description','examples', 'pretty',
'one','style','template','description','examples', 'pretty', 'charset',
'readme','all','manual_url', 'ignore', 'colon','boilerplate','merge', 'wrap',
'no_return_or_parms','no_summary','full_description','backtick_references', 'custom_see_handler',
}

View File

@ -24,7 +24,7 @@ local known_tags = {
param = 'M', see = 'M', usage = 'ML', ['return'] = 'M', field = 'M', author='M';
class = 'id', name = 'id', pragma = 'id', alias = 'id', within = 'id',
copyright = 'S', summary = 'S', description = 'S', release = 'S', license = 'S',
fixme = 'S', todo = 'S', warning = 'S', raise = 'S',
fixme = 'S', todo = 'S', warning = 'S', raise = 'S', charset = 'S',
['local'] = 'N', export = 'N', private = 'N', constructor = 'N', static = 'N';
-- project-level
module = 'T', script = 'T', example = 'T', topic = 'T', submodule='T',

View File

@ -167,6 +167,11 @@ function html.generate_output(ldoc, args, project)
return names
end
local function set_charset (ldoc,m)
m = m or ldoc.module
ldoc.doc_charset = m.tags.charset or ldoc.charset
end
local module_template,err = utils.readfile (path.join(args.template,ldoc.templ))
if not module_template then
quit("template not found at '"..args.template.."' Use -l to specify directory containing ldoc.ltp")
@ -188,6 +193,7 @@ function html.generate_output(ldoc, args, project)
if ldoc.module then
ldoc.module.info = get_module_info(ldoc.module)
end
set_charset(ldoc)
local out,err = template.substitute(module_template,{
ldoc = ldoc,
module = ldoc.module,
@ -226,6 +232,7 @@ function html.generate_output(ldoc, args, project)
for m in modules() do
ldoc.module = m
ldoc.body = m.body
set_charset(ldoc)
m.info = get_module_info(m)
if ldoc.body and m.postprocess then
ldoc.body = m.postprocess(ldoc.body)

View File

@ -2,7 +2,7 @@ return [==[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=$(ldoc.doc_charset)"/>
<head>
<title>$(ldoc.title)</title>
<link rel="stylesheet" href="$(ldoc.css)" type="text/css" />