Skip to content
Snippets Groups Projects
Commit 5c696816 authored by iaibrys's avatar iaibrys
Browse files

Add basic translator.

parent 614fd3b4
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,14 @@ theme: minima
plugins:
- jekyll-feed
asciidoctor:
attributes:
- stem
collections:
pages:
output: true
# Exclude from processing.
# The following items will not be processed, by default. Create a custom list
# to override the default setting.
......
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
messageStyle: "none",
tex2jax: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
ignoreClass: "nostem|nolatexmath"
},
asciimath2jax: {
delimiters: [["\\$", "\\$"]],
ignoreClass: "nostem|noasciimath"
},
TeX: { equationNumbers: { autoNumber: "none" } }
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>
<!DOCTYPE html>
<html lang="{{ page.lang | default: site.lang | default: "en" }}">
{%- include head.html -%}
<body>
{%- include header.html -%}
<main class="page-content" aria-label="Content">
<div class="wrapper">
{{ content }}
</div>
</main>
{%- include footer.html -%}
{%- include mathjax.html -%}
</body>
</html>
\
This diff is collapsed.
---
layout: post
title: "Welcome to Jekyll!"
date: 2019-02-07 10:29:20 -0800
categories: jekyll update
---
You’ll find this post in your `_posts` directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run `jekyll serve`, which launches a web server and auto-regenerates your site when a file is updated.
To add new posts, simply add a file in the `_posts` directory that follows the convention `YYYY-MM-DD-name-of-post.ext` and includes the necessary front matter. Take a look at the source for this post to get an idea about how it works.
Jekyll also offers powerful support for code snippets:
{% highlight ruby %}
def print_hi(name)
puts "Hi, #{name}"
end
print_hi('Tom')
#=> prints 'Hi, Tom' to STDOUT.
{% endhighlight %}
Check out the [Jekyll docs][jekyll-docs] for more info on how to get the most out of Jekyll. File all bugs/feature requests at [Jekyll’s GitHub repo][jekyll-gh]. If you have questions, you can ask them on [Jekyll Talk][jekyll-talk].
[jekyll-docs]: https://jekyllrb.com/docs/home
[jekyll-gh]: https://github.com/jekyll/jekyll
[jekyll-talk]: https://talk.jekyllrb.com/
\newcommand{\bevisslut}{$\blacksquare$}
\newenvironment{matr}[1]{\hspace{-.8mm}\begin{bmatrix}\hspace{-1mm}\begin{array}{#1}}{\end{array}\hspace{-1mm}\end{bmatrix}\hspace{-.8mm}}
\newcommand{\transp}{\hspace{-.6mm}^{\top}}
\newcommand{\maengde}[2]{\left\lbrace \hspace{-1mm} \begin{array}{c|c} #1 & #2 \end{array} \hspace{-1mm} \right\rbrace}
\newenvironment{eqnalign}[1]{\begin{equation}\begin{array}{#1}}{\end{array}\end{equation}}
\newcommand{\eqnl}{}
\newcommand{\matind}[3]{{_\mathrm{#1}\mathbf{#2}_\mathrm{#3}}}
\newcommand{\vekind}[2]{{_\mathrm{#1}\mathbf{#2}}}
\newcommand{\jac}[2]{{\mathrm{Jacobi}_\mathbf{#1} (#2)}}
\newcommand{\diver}[2]{{\mathrm{div}\mathbf{#1} (#2)}}
\newcommand{\rot}[1]{{\mathbf{rot}\mathbf{(#1)}}}
\newcommand{\am}{\mathrm{am}}
\newcommand{\gm}{\mathrm{gm}}
\newcommand{\E}{\mathrm{E}}
\newcommand{\Span}{\mathrm{span}}
\newcommand{\mU}{\mathbf{U}}
\newcommand{\mA}{\mathbf{A}}
\newcommand{\mB}{\mathbf{B}}
\newcommand{\mC}{\mathbf{C}}
\newcommand{\mD}{\mathbf{D}}
\newcommand{\mE}{\mathbf{E}}
\newcommand{\mF}{\mathbf{F}}
\newcommand{\mK}{\mathbf{K}}
\newcommand{\mI}{\mathbf{I}}
\newcommand{\mM}{\mathbf{M}}
\newcommand{\mN}{\mathbf{N}}
\newcommand{\mQ}{\mathbf{Q}}
\newcommand{\mT}{\mathbf{T}}
\newcommand{\mV}{\mathbf{V}}
\newcommand{\mW}{\mathbf{W}}
\newcommand{\mX}{\mathbf{X}}
\newcommand{\ma}{\mathbf{a}}
\newcommand{\mb}{\mathbf{b}}
\newcommand{\mc}{\mathbf{c}}
\newcommand{\md}{\mathbf{d}}
\newcommand{\me}{\mathbf{e}}
\newcommand{\mn}{\mathbf{n}}
\newcommand{\mr}{\mathbf{r}}
\newcommand{\mv}{\mathbf{v}}
\newcommand{\mw}{\mathbf{w}}
\newcommand{\mx}{\mathbf{x}}
\newcommand{\mxb}{\mathbf{x_{bet}}}
\newcommand{\my}{\mathbf{y}}
\newcommand{\mz}{\mathbf{z}}
\newcommand{\reel}{\mathbb{R}}
\newcommand{\mL}{\bm{\Lambda}} %Lambda-matrix
\newcommand{\mnul}{\mathbf{0}}
\newcommand{\trap}[1]{\mathrm{trap}(#1)}
\newcommand{\Det}{\operatorname{Det}}
\newcommand{\adj}{\operatorname{adj}}
\newcommand{\Ar}{\operatorname{Areal}}
\newcommand{\Vol}{\operatorname{Vol}}
\newcommand{\Rum}{\operatorname{Rum}}
\newcommand{\diag}{\operatorname{\bf{diag}}}
\newcommand{\bidiag}{\operatorname{\bf{bidiag}}}
\newcommand{\spanVec}[1]{\mathrm{span}\{#1\}}
\newcommand{\Div}{\operatorname{Div}}
\newcommand{\Rot}{\operatorname{\mathbf{Rot}}}
\newcommand{\Jac}{\operatorname{Jacobi}}
\newcommand{\Tan}{\operatorname{Tan}}
\newcommand{\Ort}{\operatorname{Ort}}
\newcommand{\Flux}{\operatorname{Flux}}
\newcommand{\Cmass}{\operatorname{Cm}}
\newcommand{\Imom}{\operatorname{Im}}
\newcommand{\Pmom}{\operatorname{Pm}}
\newcommand{\IS}{\operatorname{I}}
\newcommand{\IIS}{\operatorname{II}}
\newcommand{\IIIS}{\operatorname{III}}
\newcommand{\Le}{\operatorname{L}}
\newcommand{\app}{\operatorname{app}}
\newcommand{\M}{\operatorname{M}}
\newcommand{\re}{\mathrm{Re}}
\newcommand{\im}{\mathrm{Im}}
\newcommand{\compl}{\mathbb{C}} %de komplekse tal
\newcommand{\e}{\mathrm{e}} %eksponentialfunktionen. lodret 'e', og altså ikke kursiv ligesom andre bogstaver.
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# gem "rails"
gem "asciidoctor", "~> 1.5"
gem "pry", "~> 0.12.2"
GEM
remote: https://rubygems.org/
specs:
asciidoctor (1.5.8)
coderay (1.1.2)
method_source (0.9.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
PLATFORMS
ruby
DEPENDENCIES
asciidoctor (~> 1.5)
pry (~> 0.12.2)
BUNDLED WITH
2.0.1
#!/usr/bin/env ruby
# FROM https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/scripts/asciidoc-coalescer.rb
# This script coalesces the AsciiDoc content from a document master into a
# single output file. It does so by resolving all preprocessor directives in
# the document, and in any files which are included. The resolving of include
# directives is likely of most interest to users of this script.
#
# This script works by using Asciidoctor's PreprocessorReader to read and
# resolve all the lines in the specified input file. The script then writes the
# result to the output.
#
# The script only recognizes attributes passed in as options or those defined
# in the document header. It does not currently process attributes defined in
# other, arbitrary locations within the document.
# TODO
# - add cli option to write attributes passed to cli to header of document
# - escape all preprocessor directives after lines are processed (these are preprocessor directives that were escaped in the input)
# - wrap in a custom converter so it can be used as an extension
require 'asciidoctor'
require 'optparse'
require 'pry'
class TextConverter
include Asciidoctor::Converter
register_for 'text'
def initialize *args
super
outfilesuffix '.txt'
end
def convert node, transform = nil, opts = nil
case (transform ||= node.node_name)
when 'document', 'section'
[node.title, node.content].join %(\n\n)
when 'paragraph'
(node.content.tr ?\n, ' ') << ?\n
else
(transform.start_with? 'inline_') ? node.text : node.content
end
end
end
options = { attributes: [], output: '-' }
OptionParser.new do |opts|
opts.banner = 'Usage: ruby asciidoc-coalescer.rb [OPTIONS] FILE'
opts.on('-a', '--attribute key[=value]', 'A document attribute to set in the form of key[=value]') do |a|
options[:attributes] << a
end
opts.on('-o', '--output FILE', 'Write output to FILE instead of stdout.') do |o|
options[:output] = o
end
end.parse!
unless (source_file = ARGV.shift)
warn 'Please specify an AsciiDoc source file to coalesce.'
exit 1
end
unless (output_file = options[:output]) == '-'
if (output_file = File.expand_path output_file) == (File.expand_path source_file)
warn 'Source and output cannot be the same file.'
exit 1
end
end
doc = Asciidoctor.load_file source_file, safe: :unsafe, header_only: true, backend: :text, attributes: options[:attributes]
header_attr_names = (doc.instance_variable_get :@attributes_modified).to_a
header_attr_names.each {|k| doc.attributes[%(#{k}!)] = '' unless doc.attr? k }
=begin
def translate_block(block)
if block.respond_to? :lines
block.lines = block.lines
.map{ |line| line.gsub(%r{latexmath:\[\$(.*[^\\])\$\]}, 'latexmath:[\1]')}
.map{ |line| line.gsub(%r{latexmath:\[\\\[(.*[^\\])\\\]}) { |m|
['[latexmath]',
'++++',
Regexp.last_match[1],
'++++']
}}
.flatten
end
puts block.lines if block.respond_to? :lines
translate_blocks(block.blocks) unless block.blocks.empty?
end
def translate_blocks(blocks)
blocks.each{|block| translate_block block }
end
translate_blocks(doc.blocks)
doc.convert
if output_file == '-'
puts doc.content
else
File.open(output_file, 'w') {|f| f.write doc.content }
end
=end
doc = Asciidoctor.load_file source_file, safe: :unsafe, parse: false, attributes: doc.attributes
#
# process math
#
lines = doc.reader.readlines.map do |line|
if line.include? 'latexmath'
line = line.gsub(%r{latexmath:\[\$((?:(?!\$\]).)+)\$\]}, 'latexmath:[\1]')
m = line.match(%r{latexmath:\[\\\[((?:(?!\\\]).)+)\\\]})
if m
line = [
'[latexmath]',
'++++',
Regexp.last_match[1],
'++++']
end
end
line
end.flatten
#
# Process (LaTeX) includes
#
lines = lines.map do |line|
m = line.match(%r{== include (.*)\.tex})
if m
line = [
'[latexmath]',
'++++',
"include::#{m[1]}.tex[]",
'++++'
]
end
line
end.flatten
directive_stack = []
lines = lines.each_with_index.map do |line, lineno|
m = line.match(%r{=== (begin|end):(question|hint|answer)})
if m
beginend = m[1]
kind = m[2]
if beginend == 'begin'
directive_stack.push({ kind: kind, lineno: lineno, content: [] })
else
s = directive_stack.pop
if s.nil?
puts "ERROR: end without a begin #{kind} at #{lineno}: #{line}"
else
if s[:kind] != kind
puts "ERROR: unmatched #{kind} at #{lineno}; begin #{s[:kind]} on #{s[:lineno]}"
else
next ["[#{kind}]","----"] + s[:content] + ["----"]
end
end
end
next nil
else
top = directive_stack.last
if top
top[:content] << line
next nil
end
end
line
end.reject(&:nil?).flatten!
if output_file == '-'
puts lines
else
File.open(output_file, 'w') { |f| f.write lines }
end
#!/bin/bash
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
find ./website-raw/01005 -iname '*.md' -print | while read line; do
filename=$(basename $line .md)
echo "Processing file '$filename'"
cat << EOF >front_matter
---
layout: post
title: "${filename}"
date: $(date '+%Y-%m-%d %H:%M:%S %z')
---
EOF
prefix=$(date '+%Y-%m-%d-')
pandoc -s -f markdown+smart $line -t asciidoc -o $filename.adoc
ruby $ROOT/adoc_to_enote_adoc.rb $filename.adoc > $filename.adoc+enote
# cat front_matter $filename.adoc > ./course_website/_pages/$prefix$filename.adoc
cat front_matter $filename.adoc+enote > ./course_website/_pages/$filename.adoc
rm $filename.adoc
rm $filename.adoc+enote
done
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment