html_tex 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/html_tex.rb +64 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7aeb09e16f124f6014daced6df3bf27abc728ada
|
4
|
+
data.tar.gz: a18aeb8b436a0f9a789dcd9233df3b7f323f63b6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3fa104ae55bd898f408e00fb12e3e74cbaeaddf063c950460115344dad2227b47bd5dda80cf1a81087530da24c6433befc746ff0032890358e3eff142ff42130
|
7
|
+
data.tar.gz: 8fb9f80ca405be41321fe071a7c5c292e3cdb33b4d41299c1399d72c723ecb0225a2fcea7271875980ee2d2f221659ef8e8a5424cf02512fb97373fc2ffbc01f
|
data/lib/html_tex.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Converts HTML code to a TeX like syntax
|
4
|
+
class HtmlTex
|
5
|
+
def self.convert(html)
|
6
|
+
tex = html
|
7
|
+
# Convert tags that need to be opened and closed in TeX
|
8
|
+
direct_conversions.each do |html_tag, tex_tag|
|
9
|
+
tex = tex.gsub(/<\s*#{html_tag}{1}\b(\s[^>]*>|>)/i, "\\#{tex_tag}")
|
10
|
+
end
|
11
|
+
|
12
|
+
# Take care of tags which, in TeX, only need to be opened
|
13
|
+
simple_conversions.each do |html_tag, tex_tag|
|
14
|
+
tex = tex.gsub(/<\s*#{html_tag}{1}\b(\s[^>]*>|>)/i, "\\#{tex_tag} ")
|
15
|
+
# Remove closing tags, if they exist
|
16
|
+
tex = tex.gsub(/<\s*\/\s*#{html_tag}+>/i, '')
|
17
|
+
tex = tex.gsub(/<\s*\/\s*#{html_tag}{1}\b(\s[^>]*>|>)/i, '')
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create TeX environments
|
21
|
+
environment_conversions.each do |html_tag, tex_tag|
|
22
|
+
# Open environment
|
23
|
+
tex = tex.gsub(/<\s*#{html_tag}{1}\b(\s[^>]*>|>)/i, "\\begin{#{tex_tag}}")
|
24
|
+
# Close environment
|
25
|
+
tex = tex.gsub(/<\s*\/\s*#{html_tag}{1}\b(\s[^>]*>|>)/i, "\\end{#{tex_tag}}")
|
26
|
+
end
|
27
|
+
|
28
|
+
# Close remaining tags
|
29
|
+
tex = tex.gsub(/<\s*\/\s*([a-zA-Z]+)>/, '}')
|
30
|
+
tex
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.direct_conversions
|
34
|
+
{
|
35
|
+
h1: 'part{',
|
36
|
+
h2: 'chapter{',
|
37
|
+
h3: 'section{',
|
38
|
+
h4: 'subsection{',
|
39
|
+
h5: 'subsubsection{',
|
40
|
+
h6: 'textbf{',
|
41
|
+
i: 'textit{',
|
42
|
+
u: 'underline{',
|
43
|
+
b: 'textbf{',
|
44
|
+
strong: 'textbf{',
|
45
|
+
br: '\\'
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.simple_conversions
|
50
|
+
{
|
51
|
+
p: '\\',
|
52
|
+
hr: 'hrule',
|
53
|
+
li: 'item'
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.environment_conversions
|
58
|
+
{
|
59
|
+
ol: 'enumerate',
|
60
|
+
ul: 'itemize',
|
61
|
+
body: 'document'
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html_tex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Advicefront
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: developers@advicefront.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/html_tex.rb
|
20
|
+
homepage: https://advicefront.com
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.6.13
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Simple conversion tool from HTML to TeX. Ignores all styling.
|
44
|
+
test_files: []
|