Made a html output!
This commit is contained in:
parent
0c0d20c998
commit
9c292c7fa7
11 changed files with 268 additions and 18 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@
|
|||
my_book.tex
|
||||
tmp/
|
||||
site/
|
||||
include/MathJax
|
||||
|
|
|
@ -119,3 +119,7 @@ You can also declare macro that will be processed after the file was transformed
|
|||
|
||||
In markdown, you simply write %macroname or %code
|
||||
and it will be transformed correctly in your pdf.
|
||||
|
||||
# HTML render
|
||||
|
||||
To render math properly install MathJax into the `site/js` directory
|
||||
|
|
35
Rakefile
35
Rakefile
|
@ -7,7 +7,8 @@ CLEAN.include('**/*.{aux,log,out}')
|
|||
CLEAN.include('tmp/**/*')
|
||||
CLOBBER.include('**/*.pdf')
|
||||
CLOBBER.include('content/**/*.tex')
|
||||
CLOBBER.include('site/**/*')
|
||||
CLOBBER.include('site/**/*.html')
|
||||
CLOBBER.include('site/include/*')
|
||||
|
||||
task :default => [:compile]
|
||||
|
||||
|
@ -64,6 +65,8 @@ task :khtml do
|
|||
require 'kramdown'
|
||||
require 'filters/markdown_macros'
|
||||
require 'filters/mkd_post_latex_macros_to_html'
|
||||
require 'filters/html_template'
|
||||
require 'filters/mathjax'
|
||||
|
||||
class KrambookCompile
|
||||
require 'config_html.rb'
|
||||
|
@ -95,7 +98,7 @@ task :khtml do
|
|||
@filelist.map do |source,dest|
|
||||
%{<div class="block left">
|
||||
<h3>
|
||||
<a href="#{dest.sub(/^tmp\//,'')}">
|
||||
<a href="#{dest.sub(/^site\//,'')}">
|
||||
#{File::basename(dest,'.html')}
|
||||
<span class="nicer">»</span>
|
||||
</a>
|
||||
|
@ -111,7 +114,7 @@ task :khtml do
|
|||
# puts "AFTER TITLE: " + txt
|
||||
txt.sub!( %r{<!-- HTML HEADER -->},@html_headers)
|
||||
# puts "AFTER HTML HEADER: " + txt
|
||||
fic=File.new("tmp/#{@pdfname}.html","w")
|
||||
fic=File.new("site/index.html","w")
|
||||
fic.write(txt)
|
||||
fic.close
|
||||
end
|
||||
|
@ -125,19 +128,40 @@ task :khtml do
|
|||
|
||||
@postfilters=[]
|
||||
@postfilters<<=MarkdownPostLatexMacrosToHTML.new
|
||||
html_template=HTMLTemplate.new
|
||||
html_template.template=@general_template
|
||||
html_template.title=@title
|
||||
html_template.subtitle=@subtitle
|
||||
html_template.author=@author
|
||||
html_template.html_headers=@html_headers
|
||||
html_template.homeURL="index.html"
|
||||
@postfilters<<=html_template
|
||||
@postfilters<<=MathJax.new
|
||||
|
||||
@filelist=Dir.glob("content/**/*.md").sort.map do |fic|
|
||||
[ fic, fic.sub(/^content\//,"tmp/").sub(/.md$/,".html") ]
|
||||
[ fic, fic.sub(/^content\//,"site/").sub(/.md$/,".html") ]
|
||||
end
|
||||
end
|
||||
|
||||
def run
|
||||
i=-1
|
||||
@filelist.each do |doublon|
|
||||
i+=1
|
||||
source=doublon[0]
|
||||
dest=doublon[1]
|
||||
puts source
|
||||
|
||||
# read and compile in LaTeX the .md file
|
||||
if (i+1)<@filelist.size
|
||||
@postfilters[1].nextURL = '/' + @filelist[i + 1][1].gsub('site/','')
|
||||
else
|
||||
@postfilters[1].nextURL = "#"
|
||||
end
|
||||
if (i-1)>=0
|
||||
@postfilters[1].prevURL = '/' + @filelist[i - 1][1].gsub('site/','')
|
||||
else
|
||||
@postfilters[1].prevURL = "#"
|
||||
end
|
||||
text=compile_text( File.new(source,"r").read )
|
||||
|
||||
# create directory if necessary
|
||||
|
@ -155,8 +179,7 @@ task :khtml do
|
|||
# write the .tex file containing all includes
|
||||
process_template
|
||||
|
||||
system("cp -rf include tmp/")
|
||||
# system("open tmp/#{@pdfname}.html")
|
||||
system("cp -rf include site/")
|
||||
end
|
||||
end
|
||||
KrambookCompile.new.run
|
||||
|
|
50
config.ru
Normal file
50
config.ru
Normal file
|
@ -0,0 +1,50 @@
|
|||
require 'rubygems'
|
||||
require 'rack'
|
||||
require 'rack/contrib'
|
||||
require 'rack-rewrite'
|
||||
require 'mime/types'
|
||||
|
||||
use Rack::Deflater
|
||||
use Rack::ETag
|
||||
module ::Rack
|
||||
class TryStatic < Static
|
||||
|
||||
def initialize(app, options)
|
||||
super
|
||||
@try = ([''] + Array(options.delete(:try)) + [''])
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@next = 0
|
||||
while @next < @try.size && 404 == (resp = super(try_next(env)))[0]
|
||||
@next += 1
|
||||
end
|
||||
404 == resp[0] ? @app.call : resp
|
||||
end
|
||||
|
||||
private
|
||||
def try_next(env)
|
||||
env.merge('PATH_INFO' => env['PATH_INFO'] + @try[@next])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# use Rack::Rewrite do
|
||||
# r302 %r{/(Softwares.*)}, 'http://web.me.com/yann.esposito/$1'
|
||||
# r302 %r{/(Perso.*)}, 'http://web.me.com/yann.esposito/$1'
|
||||
# r302 %r{/YPassword(.*)}, '/Scratch/en/softwares/ypassword/iphoneweb'
|
||||
# r302 %r{/(Bastien.*)}, 'http://web.me.com/yann.esposito/$1'
|
||||
# end
|
||||
|
||||
use Rack::TryStatic,
|
||||
:root => "site/", # static files root dir
|
||||
:urls => %w[/], # match all requests
|
||||
:try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially
|
||||
|
||||
errorFile='site/404.html'
|
||||
run lambda { [404, {
|
||||
"Last-Modified" => File.mtime(errorFile).httpdate,
|
||||
"Content-Type" => "text/html",
|
||||
"Content-Length" => File.size(errorFile).to_s
|
||||
}, File.read(errorFile)] }
|
|
@ -15,5 +15,6 @@
|
|||
# change the template file in case latex_headers is not enough
|
||||
# Remember to not remove lines begining by %%#
|
||||
# look at include/template.tex for example
|
||||
@template_file="include/template.html"
|
||||
@template_file="include/toc_template.html"
|
||||
@general_template="include/template.html"
|
||||
|
||||
|
|
30
filters/html_template.rb
Normal file
30
filters/html_template.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
class HTMLTemplate
|
||||
attr_accessor :template
|
||||
attr_accessor :title
|
||||
attr_accessor :subtitle
|
||||
attr_accessor :author
|
||||
attr_accessor :nextURL
|
||||
attr_accessor :prevURL
|
||||
attr_accessor :homeURL
|
||||
attr_accessor :html_headers
|
||||
def run (content)
|
||||
res=File.read(@template)
|
||||
res.gsub(/<!-- Content -->/) do
|
||||
content
|
||||
end.gsub(/<!-- Title -->/) do
|
||||
@title
|
||||
end.gsub(/<!-- Subtitle -->/) do
|
||||
@subtitle
|
||||
end.gsub(/<!-- Author -->/) do
|
||||
@author
|
||||
end.gsub(%{/NEXT_URL/}) do
|
||||
@nextURL
|
||||
end.gsub(%{/PREV_URL/}) do
|
||||
@prevURL
|
||||
end.gsub(%{/HOME_URL/}) do
|
||||
@homeURL
|
||||
end.gsub(%{<!-- HTML HEADERS -->}) do
|
||||
@html_headers
|
||||
end
|
||||
end
|
||||
end
|
7
filters/mathjax.rb
Normal file
7
filters/mathjax.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class MathJax
|
||||
def run (content)
|
||||
content.gsub(%r{<div class="math">((.|\n)*?)</div>}) do
|
||||
'$$'+$1+'$$'
|
||||
end
|
||||
end
|
||||
end
|
File diff suppressed because one or more lines are too long
|
@ -4,20 +4,27 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<link rel="stylesheet" type="text/css" href="include/main.css" />
|
||||
|
||||
<!-- HTML HEADER -->
|
||||
<title><!-- Title --> by <!-- Author --></title>
|
||||
<link rel="stylesheet" type="text/css" href="/include/main.css" />
|
||||
<script type="text/javascript" src="/js/MathJax/MathJax.js"></script>
|
||||
<!-- HTML HEADERS -->
|
||||
<title><!-- Title --> (<!-- Subtitle -->) by <!-- Author --></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1 style="font-size: 5em; font-weight: normal;"> <!-- Title --> </h1>
|
||||
<div id="titre">
|
||||
<h2> <!-- Subtitle --> </h2>
|
||||
<h3><em>by</em> <!-- Author --> </h3>
|
||||
</div>
|
||||
|
||||
<div class="navigation">
|
||||
<div class="home"><a href="/HOME_URL/">« Home</a></div>
|
||||
<div class="navigationprev"><a href="/PREV_URL/"><span class="nicer">«</span> previous</a></div>
|
||||
<div class="navigationnext"><a href="/NEXT_URL/">next <span class="nicer">»</span></a></div>
|
||||
</div>
|
||||
<div id="afterhead" style="padding-top: 2em; font-size: 1.3em;">
|
||||
<!-- INCLUDES -->
|
||||
<div class="corps">
|
||||
<!-- Content -->
|
||||
</div>
|
||||
<div class="navigation">
|
||||
<div class="navigationprev"><a href="/PREV_URL/"><span class="nicer">«</span> previous</a></div>
|
||||
<div class="navigationnext"><a href="/NEXT_URL/">next <span class="nicer">»</span></a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
26
include/toc_template.html
Normal file
26
include/toc_template.html
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<link rel="stylesheet" type="text/css" href="include/main.css" />
|
||||
|
||||
<!-- HTML HEADER -->
|
||||
<title><!-- Title --> by <!-- Author --></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<h1 style="font-size: 5em; font-weight: normal;"> <!-- Title --> </h1>
|
||||
<div id="titre">
|
||||
<h2> <!-- Subtitle --> </h2>
|
||||
<h3><em>by</em> <!-- Author --> </h3>
|
||||
</div>
|
||||
<div id="afterhead" style="padding-top: 2em; font-size: 1.3em;">
|
||||
<!-- INCLUDES -->
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
101
svgsite/index.html
Normal file
101
svgsite/index.html
Normal file
|
@ -0,0 +1,101 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Krambook</title>
|
||||
<script src="https://www.google.com/jsapi"></script>
|
||||
<script>
|
||||
google.load('jquery', '1.4.4');
|
||||
|
||||
var nb_pages=0;
|
||||
|
||||
function changeTo(n) {
|
||||
page = n;
|
||||
if (page == 1) {
|
||||
page=1;
|
||||
$('#previous').addClass('disable');
|
||||
$('#first').addClass('disable');
|
||||
} else if (page == nb_pages) {
|
||||
$('#next').addClass('disable');
|
||||
} else if (page<1) {
|
||||
page=1;
|
||||
return;
|
||||
} else if (page>nb_pages) {
|
||||
page=nb_pages;
|
||||
return;
|
||||
} else {
|
||||
$('#previous').removeClass('disable');
|
||||
$('#first').removeClass('disable');
|
||||
$('#next').removeClass('disable');
|
||||
}
|
||||
fic = "krambook-" + page + ".svg";
|
||||
console.log("fic = " + fic);
|
||||
$('#frame').attr('src', fic );
|
||||
$('#nbpages').text("Page "+ page +" / "+nb_pages);
|
||||
}
|
||||
|
||||
</script>
|
||||
<script>
|
||||
var page=1;
|
||||
google.setOnLoadCallback( function() {
|
||||
$('#first').click( function() { changeTo(1); });
|
||||
$('#previous').click( function() { changeTo(page-1); });
|
||||
$('#previous').addClass('disable');
|
||||
$('#next').click( function() { changeTo(page+1); });
|
||||
$('#nbpages').text("Page 1 / "+nb_pages);
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
#leftcolumn {float: left; width: 7em}
|
||||
#rightcolumn {float: right; width: 7em}
|
||||
.button {
|
||||
text-shadow: 0 1px 0 #eee;
|
||||
border: 1px solid #666;
|
||||
width: 7em;
|
||||
height: 3em;
|
||||
background: #ccc;
|
||||
color: #333;
|
||||
border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
-webkit-border-radius: 2px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
margin-bottom: 1em;
|
||||
margin-top: 1em;
|
||||
line-height: 3em; }
|
||||
|
||||
.disable {
|
||||
cursor: default;
|
||||
opacity: .3 }
|
||||
|
||||
#nbpages{
|
||||
border: 1px solid #666;
|
||||
width: 7em;
|
||||
height: 3em;
|
||||
line-height: 3em;
|
||||
background: #eee;
|
||||
text-align: center; }
|
||||
|
||||
#content {margin-left: auto; margin-right: auto; text-align: center}
|
||||
#frame {
|
||||
text-align: center; margin-left: auto; margin-right: auto;
|
||||
width: 492pt; height: 672pt; border: 1px solid #ccc}
|
||||
#who { position: fixed; bottom: 2px; right: 2px; text-align: right; font-size: .7em; }
|
||||
a { color: #888; text-decoration: none; border: none; }
|
||||
a:hover { color: #dc3; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="leftcolumn">
|
||||
<div id="previous" class="button">« Previous</div>
|
||||
<div id="first" class="button">« First</div>
|
||||
</div>
|
||||
<div id="rightcolumn">
|
||||
<div id="next" class="button">Next »</div>
|
||||
<div id="nbpages"> Page 1 / ?? </div>
|
||||
<div id="who">Generated with <a href="http://github.com/yogsototh/krambook.git">krambook</a></div>
|
||||
</div>
|
||||
<div id="content">
|
||||
<iframe id="frame" src="krambook-1.svg" style=""frameborder="0" scrolling="no" ></iframe>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue