htmltoooxml 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b53b2db56bbccc5a69bb1ad0c8f5c40384059474
4
+ data.tar.gz: 134380508d092984330039ae887ec0d83a04ef0d
5
+ SHA512:
6
+ metadata.gz: d85a4c133882790d77edf0ae9a61baa92add3fdd83ded8e65cc6ae2bce0e9a47bcafc7893d607040820663374fe30a3fc9971b2128d28e1fc2319e724242d924
7
+ data.tar.gz: c292949f82a18112ae13a69b5317f1cca28e5864d4163deec06cd73c1a2acae0cec507a8db12d365e1194412ea9853d54ced3e37f6589df436e756b47f3cbce3
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in html_to_ooxml.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Justin Boynton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # html_to_ooxml
2
+
3
+ Convert basic html to ooxml standard for inclusion in PPTX files
4
+
5
+ Heavily based on the htmltoword gem https://github.com/karnov/htmltoword
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'htmltoooxml'
13
+ ```
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install html_to_ooxml
21
+
22
+ ## Usage
23
+
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/stylefoundry/html_to_ooxml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ task :default => :spec
4
+ RSpec::Core::RakeTask.new
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "htmltooxml"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'htmltoooxml/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "htmltoooxml"
8
+ spec.version = Htmltoooxml::VERSION
9
+ spec.authors = ["Justin Boynton"]
10
+ spec.email = ["justin.boynton@spicerack.co.uk"]
11
+
12
+ spec.summary = %q{Parse HTML and convert to open office xml for powerpoint}
13
+ spec.description = %q{Parse HTML and convert to open office xml for powerpoint}
14
+ spec.homepage = "https://github.com/stylefoundry"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+
33
+ spec.add_dependency 'nokogiri'
34
+ end
@@ -0,0 +1,10 @@
1
+ module Htmltoooxml
2
+ class Configuration
3
+ attr_accessor :default_xslt_path, :custom_xslt_path
4
+
5
+ def initialize
6
+ @default_xslt_path = File.join(File.expand_path('../', __FILE__), 'xslt')
7
+ @custom_xslt_path = File.join(File.expand_path('../', __FILE__), 'xslt')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ module Htmltoooxml
2
+ class Document
3
+ include XSLTHelper
4
+
5
+ class << self
6
+
7
+ end
8
+
9
+ def initialize()
10
+ @replaceable_files = {}
11
+ end
12
+
13
+ def transform_doc_xml(source, extras = false)
14
+ transformed_source = xslt(stylesheet_name: 'cleanup').transform(source)
15
+ transformed_source = xslt(stylesheet_name: 'inline_elements').transform(transformed_source)
16
+ transform_and_replace(transformed_source, document_xslt(extras), extras)
17
+ end
18
+
19
+ private
20
+
21
+ def transform_and_replace(source, stylesheet_path, remove_ns = false)
22
+ stylesheet = xslt(stylesheet_path: stylesheet_path)
23
+ content = stylesheet.apply_to(source)
24
+ content.gsub!(/\s*xmlns:(\w+)="(.*?)\s*"/, '') if remove_ns
25
+ content
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module Htmltoooxml
2
+ module XSLTHelper
3
+ def document_xslt(extras = false)
4
+ file_name = extras ? 'htmltoooxml' : 'base'
5
+ xslt_path(file_name)
6
+ end
7
+
8
+ def xslt_path(template_name)
9
+ File.join(Htmltoooxml.config.default_xslt_path, "#{template_name}.xslt")
10
+ end
11
+
12
+ def xslt(stylesheet_name: nil, stylesheet_path: nil)
13
+ return Nokogiri::XSLT(File.open(stylesheet_path)) if stylesheet_path
14
+ Nokogiri::XSLT(File.open(xslt_path(stylesheet_name)))
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Htmltoooxml
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,345 @@
1
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
+ xmlns:a="http://schemas.openxmlformats.org/presentationml/2006/main"
3
+ xmlns:o="urn:schemas-microsoft-com:office:office"
4
+ xmlns:v="urn:schemas-microsoft-com:vml"
5
+ xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
6
+ xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
7
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
8
+ xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
9
+ xmlns:msxsl="urn:schemas-microsoft-com:xslt"
10
+ xmlns:ext="http://www.xmllab.net/wordml2html/ext"
11
+ xmlns:java="http://xml.apache.org/xalan/java"
12
+ xmlns:str="http://exslt.org/strings"
13
+ xmlns:func="http://exslt.org/functions"
14
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
15
+ version="1.0"
16
+ exclude-result-prefixes="java msxsl ext a o v WX aml w10"
17
+ extension-element-prefixes="func">
18
+ <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" indent="yes" />
19
+ <xsl:include href="./functions.xslt"/>
20
+ <xsl:include href="./tables.xslt"/>
21
+ <xsl:include href="./links.xslt"/>
22
+
23
+ <xsl:template match="/">
24
+ <xsl:apply-templates />
25
+ </xsl:template>
26
+
27
+ <xsl:template match="head" />
28
+
29
+ <xsl:template match="body">
30
+ <xsl:comment>
31
+ KNOWN BUGS:
32
+ div
33
+ h2
34
+ div
35
+ textnode (WONT BE WRAPPED IN A a:P)
36
+ div
37
+ table
38
+ span
39
+ text
40
+ </xsl:comment>
41
+ <xsl:apply-templates/>
42
+ </xsl:template>
43
+
44
+ <xsl:template match="body/*[not(*)]">
45
+ <a:p>
46
+ <xsl:call-template name="text-alignment" />
47
+ <a:r>
48
+ <a:t xml:space="preserve"><xsl:value-of select="."/></a:t>
49
+ </a:r>
50
+ </a:p>
51
+ </xsl:template>
52
+
53
+
54
+ <xsl:template match="br[not(ancestor::p) and not(ancestor::div) and not(ancestor::td|ancestor::li) or
55
+ (preceding-sibling::div or following-sibling::div or preceding-sibling::p or following-sibling::p)]">
56
+ <a:p>
57
+ <a:r></a:r>
58
+ </a:p>
59
+ </xsl:template>
60
+
61
+ <xsl:template match="br[(ancestor::li or ancestor::td) and
62
+ (preceding-sibling::div or following-sibling::div or preceding-sibling::p or following-sibling::p)]">
63
+ <a:r>
64
+ <a:br />
65
+ </a:r>
66
+ </xsl:template>
67
+
68
+ <xsl:template match="br">
69
+ <a:r>
70
+ <a:br />
71
+ </a:r>
72
+ </xsl:template>
73
+
74
+ <xsl:template match="pre">
75
+ <a:p>
76
+ <xsl:apply-templates />
77
+ </a:p>
78
+ </xsl:template>
79
+
80
+ <xsl:template match="div[not(ancestor::li) and not(ancestor::td) and not(ancestor::th) and not(ancestor::p) and not(descendant::div) and not(descendant::p) and not(descendant::h1) and not(descendant::h2) and not(descendant::h3) and not(descendant::h4) and not(descendant::h5) and not(descendant::h6) and not(descendant::table) and not(descendant::li) and not (descendant::pre)]">
81
+ <xsl:comment>Divs should create a p if nothing above them has and nothing below them will</xsl:comment>
82
+ <a:p>
83
+ <xsl:call-template name="text-alignment" />
84
+ <xsl:apply-templates />
85
+ </a:p>
86
+ </xsl:template>
87
+
88
+ <xsl:template match="div">
89
+ <xsl:apply-templates />
90
+ </xsl:template>
91
+
92
+ <!-- TODO: make this prettier. Headings shouldn't enter in template from L51 -->
93
+ <xsl:template match="body/h1|body/h2|body/h3|body/h4|body/h5|body/h6|h1|h2|h3|h4|h5|h6">
94
+ <xsl:variable name="length" select="string-length(name(.))"/>
95
+ <a:p>
96
+ <a:pPr>
97
+ <a:pStyle a:val="Heading{substring(name(.),$length)}"/>
98
+ </a:pPr>
99
+ <a:r>
100
+ <a:t xml:space="preserve"><xsl:value-of select="."/></a:t>
101
+ </a:r>
102
+ </a:p>
103
+ </xsl:template>
104
+
105
+ <xsl:template match="p[not(ancestor::li)]">
106
+ <a:p>
107
+ <a:pPr marL="0" indent="0">
108
+ <a:spcAft>
109
+ <a:spcPts val="600"/>
110
+ </a:spcAft>
111
+ <a:buNone/>
112
+ </a:pPr>
113
+ <xsl:call-template name="text-alignment" />
114
+ <xsl:apply-templates />
115
+ </a:p>
116
+ </xsl:template>
117
+
118
+ <xsl:template match="ol|ul">
119
+ <xsl:param name="global_level" select="count(preceding::ol[not(ancestor::ol or ancestor::ul)]) + count(preceding::ul[not(ancestor::ol or ancestor::ul)]) + 1"/>
120
+ <xsl:apply-templates>
121
+ <xsl:with-param name="global_level" select="$global_level" />
122
+ </xsl:apply-templates>
123
+ </xsl:template>
124
+
125
+ <xsl:template name="listItem" match="li">
126
+ <xsl:param name="global_level" />
127
+ <xsl:param name="preceding-siblings" select="0"/>
128
+ <xsl:for-each select="node()">
129
+ <xsl:choose>
130
+ <xsl:when test="self::br">
131
+ <a:p>
132
+ <a:pPr>
133
+ <a:pStyle a:val="ListParagraph"></a:pStyle>
134
+ <a:numPr>
135
+ <a:ilvl a:val="0"/>
136
+ <a:numId a:val="0"/>
137
+ </a:numPr>
138
+ </a:pPr>
139
+ <a:r></a:r>
140
+ </a:p>
141
+ </xsl:when>
142
+ <xsl:when test="self::ol|self::ul">
143
+ <xsl:apply-templates>
144
+ <xsl:with-param name="global_level" select="$global_level" />
145
+ </xsl:apply-templates>
146
+ </xsl:when>
147
+ <xsl:when test="not(descendant::li)"> <!-- simpler div, p, headings, etc... -->
148
+ <xsl:variable name="ilvl" select="count(ancestor::ol) + count(ancestor::ul) - 1"></xsl:variable>
149
+ <xsl:choose>
150
+ <xsl:when test="$preceding-siblings + count(preceding-sibling::*) > 0">
151
+ <a:p>
152
+ <a:pPr>
153
+ <a:pStyle a:val="ListParagraph"></a:pStyle>
154
+ <a:numPr>
155
+ <a:ilvl a:val="0"/>
156
+ <a:numId a:val="0"/>
157
+ </a:numPr>
158
+ <a:ind a:left="{720 * ($ilvl + 1)}"/>
159
+ </a:pPr>
160
+ <xsl:apply-templates/>
161
+ </a:p>
162
+ </xsl:when>
163
+ <xsl:otherwise>
164
+ <a:p>
165
+ <a:pPr>
166
+ <a:pStyle a:val="ListParagraph"></a:pStyle>
167
+ <a:numPr>
168
+ <a:ilvl a:val="{$ilvl}"/>
169
+ <a:numId a:val="{$global_level}"/>
170
+ </a:numPr>
171
+ </a:pPr>
172
+ <xsl:apply-templates/>
173
+ </a:p>
174
+ </xsl:otherwise>
175
+ </xsl:choose>
176
+ </xsl:when>
177
+ <xsl:otherwise> <!-- mixed things div having list and stuff content... -->
178
+ <xsl:call-template name="listItem">
179
+ <xsl:with-param name="global_level" select="$global_level" />
180
+ <xsl:with-param name="preceding-siblings" select="$preceding-siblings + count(preceding-sibling::*)" />
181
+ </xsl:call-template>
182
+ </xsl:otherwise>
183
+ </xsl:choose>
184
+ </xsl:for-each>
185
+ </xsl:template>
186
+
187
+ <xsl:template match="span[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
188
+ |a[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
189
+ |small[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
190
+ |strong[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
191
+ |em[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
192
+ |i[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
193
+ |b[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]
194
+ |u[not(ancestor::td) and not(ancestor::li) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
195
+ <xsl:comment>
196
+ In the following situation:
197
+
198
+ div
199
+ h2
200
+ span
201
+ textnode
202
+ span
203
+ textnode
204
+ p
205
+
206
+ The div template will not create a a:p because the div contains a h2. Therefore we need to wrap the inline elements span|a|small in a p here.
207
+ </xsl:comment>
208
+ <a:p>
209
+ <xsl:choose>
210
+ <xsl:when test="self::a[starts-with(@href, 'http://') or starts-with(@href, 'https://')]">
211
+ <xsl:call-template name="link" />
212
+ </xsl:when>
213
+ <xsl:otherwise>
214
+ <xsl:apply-templates />
215
+ </xsl:otherwise>
216
+ </xsl:choose>
217
+ </a:p>
218
+ </xsl:template>
219
+
220
+ <xsl:template match="text()[not(parent::li) and not(parent::td) and not(parent::pre) and (preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div)]">
221
+ <xsl:comment>
222
+ In the following situation:
223
+
224
+ div
225
+ h2
226
+ textnode
227
+ p
228
+
229
+ The div template will not create a a:p because the div contains a h2. Therefore we need to wrap the textnode in a p here.
230
+ </xsl:comment>
231
+ <a:p>
232
+ <a:r>
233
+ <a:t xml:space="preserve"><xsl:value-of select="."/></a:t>
234
+ </a:r>
235
+ </a:p>
236
+ </xsl:template>
237
+
238
+ <xsl:template match="span[contains(concat(' ', @class, ' '), ' h ')]">
239
+ <xsl:comment>
240
+ This template adds MS Word highlighting ability.
241
+ </xsl:comment>
242
+ <xsl:variable name="color">
243
+ <xsl:choose>
244
+ <xsl:when test="./@data-style='pink'">magenta</xsl:when>
245
+ <xsl:when test="./@data-style='blue'">cyan</xsl:when>
246
+ <xsl:when test="./@data-style='orange'">darkYellow</xsl:when>
247
+ <xsl:otherwise><xsl:value-of select="./@data-style"/></xsl:otherwise>
248
+ </xsl:choose>
249
+ </xsl:variable>
250
+ <xsl:choose>
251
+ <xsl:when test="preceding-sibling::h1 or preceding-sibling::h2 or preceding-sibling::h3 or preceding-sibling::h4 or preceding-sibling::h5 or preceding-sibling::h6 or preceding-sibling::table or preceding-sibling::p or preceding-sibling::ol or preceding-sibling::ul or preceding-sibling::div or following-sibling::h1 or following-sibling::h2 or following-sibling::h3 or following-sibling::h4 or following-sibling::h5 or following-sibling::h6 or following-sibling::table or following-sibling::p or following-sibling::ol or following-sibling::ul or following-sibling::div">
252
+ <a:p>
253
+ <a:r>
254
+ <a:rPr>
255
+ <a:highlight a:val="{$color}"/>
256
+ </a:rPr>
257
+ <a:t xml:space="preserve"><xsl:value-of select="."/></a:t>
258
+ </a:r>
259
+ </a:p>
260
+ </xsl:when>
261
+ <xsl:otherwise>
262
+ <a:r>
263
+ <a:rPr>
264
+ <a:highlight a:val="{$color}"/>
265
+ </a:rPr>
266
+ <a:t xml:space="preserve"><xsl:value-of select="."/></a:t>
267
+ </a:r>
268
+ </xsl:otherwise>
269
+ </xsl:choose>
270
+ </xsl:template>
271
+
272
+ <xsl:template match="div[contains(concat(' ', @class, ' '), ' -page-break ')]">
273
+ <a:p>
274
+ <a:r>
275
+ <a:br a:type="page" />
276
+ </a:r>
277
+ </a:p>
278
+ <xsl:apply-templates />
279
+ </xsl:template>
280
+
281
+ <xsl:template match="details" />
282
+
283
+ <xsl:template match="text()">
284
+ <xsl:if test="string-length(.) > 0">
285
+ <a:r>
286
+ <xsl:if test="ancestor::i">
287
+ <a:rPr>
288
+ <a:i />
289
+ </a:rPr>
290
+ </xsl:if>
291
+ <xsl:if test="ancestor::b">
292
+ <a:rPr>
293
+ <a:b />
294
+ </a:rPr>
295
+ </xsl:if>
296
+ <xsl:if test="ancestor::u">
297
+ <a:rPr>
298
+ <a:u a:val="single"/>
299
+ </a:rPr>
300
+ </xsl:if>
301
+ <xsl:if test="ancestor::s">
302
+ <a:rPr>
303
+ <a:strike a:val="true"/>
304
+ </a:rPr>
305
+ </xsl:if>
306
+ <xsl:if test="ancestor::sub">
307
+ <a:rPr>
308
+ <a:vertAlign a:val="subscript"/>
309
+ </a:rPr>
310
+ </xsl:if>
311
+ <xsl:if test="ancestor::sup">
312
+ <a:rPr>
313
+ <a:vertAlign a:val="superscript"/>
314
+ </a:rPr>
315
+ </xsl:if>
316
+ <a:rPr lang="en-US" sz="1600" b="0" noProof="0" dirty="0" smtClean="0" />
317
+ <a:t xml:space="preserve"><xsl:value-of select="."/></a:t>
318
+ </a:r>
319
+ </xsl:if>
320
+ </xsl:template>
321
+
322
+ <xsl:template match="*">
323
+ <xsl:apply-templates/>
324
+ </xsl:template>
325
+
326
+ <xsl:template name="text-alignment">
327
+ <xsl:param name="class" select="@class" />
328
+ <xsl:param name="style" select="@style" />
329
+ <xsl:variable name="alignment">
330
+ <xsl:choose>
331
+ <xsl:when test="contains(concat(' ', $class, ' '), ' center ') or contains(translate(normalize-space($style),' ',''), 'text-align:center')">center</xsl:when>
332
+ <xsl:when test="contains(concat(' ', $class, ' '), ' right ') or contains(translate(normalize-space($style),' ',''), 'text-align:right')">right</xsl:when>
333
+ <xsl:when test="contains(concat(' ', $class, ' '), ' left ') or contains(translate(normalize-space($style),' ',''), 'text-align:left')">left</xsl:when>
334
+ <xsl:when test="contains(concat(' ', $class, ' '), ' justify ') or contains(translate(normalize-space($style),' ',''), 'text-align:justify')">both</xsl:when>
335
+ <xsl:otherwise></xsl:otherwise>
336
+ </xsl:choose>
337
+ </xsl:variable>
338
+ <xsl:if test="string-length(normalize-space($alignment)) > 0">
339
+ <a:pPr>
340
+ <a:jc a:val="{$alignment}"/>
341
+ </a:pPr>
342
+ </xsl:if>
343
+ </xsl:template>
344
+
345
+ </xsl:stylesheet>
@@ -0,0 +1,71 @@
1
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
+ xmlns:str="http://exslt.org/strings"
3
+ xmlns:func="http://exslt.org/functions"
4
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
5
+ version="1.0"
6
+ exclude-result-prefixes="java msxsl ext a o v WX aml w10"
7
+ extension-element-prefixes="func">
8
+ <xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" indent="yes"/>
9
+
10
+ <xsl:template match="/">
11
+ <xsl:apply-templates/>
12
+ </xsl:template>
13
+
14
+ <xsl:template match="head"/>
15
+
16
+ <!-- Elements not supported -->
17
+ <xsl:template match="applet"/>
18
+ <xsl:template match="area"/>
19
+ <xsl:template match="audio"/>
20
+ <xsl:template match="base"/>
21
+ <xsl:template match="basefont"/>
22
+ <xsl:template match="canvas"/>
23
+ <xsl:template match="command"/>
24
+ <xsl:template match="font"/>
25
+ <xsl:template match="iframe"/>
26
+ <xsl:template match="img"/>
27
+ <xsl:template match="isindex"/>
28
+ <xsl:template match="map"/>
29
+ <xsl:template match="noframes"/>
30
+ <xsl:template match="noscript"/>
31
+ <xsl:template match="object"/>
32
+ <xsl:template match="param"/>
33
+ <xsl:template match="script"/>
34
+ <xsl:template match="source"/>
35
+ <xsl:template match="style"/>
36
+ <xsl:template match="video"/>
37
+
38
+ <!-- Elements currently being handled as normal text. Remove tags only -->
39
+ <xsl:template match="abbr"><xsl:apply-templates/></xsl:template>
40
+ <xsl:template match="acronym"><xsl:apply-templates/></xsl:template>
41
+ <xsl:template match="bdi"><xsl:apply-templates/></xsl:template>
42
+ <xsl:template match="bdo"><xsl:apply-templates/></xsl:template>
43
+ <xsl:template match="big"><xsl:apply-templates/></xsl:template>
44
+ <xsl:template match="code"><xsl:apply-templates/></xsl:template>
45
+ <xsl:template match="kbd"><xsl:apply-templates/></xsl:template>
46
+ <xsl:template match="samp"><xsl:apply-templates/></xsl:template>
47
+ <xsl:template match="small"><xsl:apply-templates/></xsl:template>
48
+ <xsl:template match="tt"><xsl:apply-templates/></xsl:template>
49
+ <xsl:template match="var"><xsl:apply-templates/></xsl:template>
50
+
51
+ <!-- Inline elements transformations -->
52
+ <xsl:template match="cite"><i><xsl:apply-templates/></i></xsl:template>
53
+ <xsl:template match="del"><s><xsl:apply-templates/></s></xsl:template>
54
+ <xsl:template match="dfn"><i><xsl:apply-templates/></i></xsl:template>
55
+ <xsl:template match="em"><i><xsl:apply-templates/></i></xsl:template>
56
+ <xsl:template match="ins"><u><xsl:apply-templates/></u></xsl:template>
57
+ <xsl:template match="mark"><span class="h" data-style="yellow"><xsl:apply-templates/></span></xsl:template>
58
+ <xsl:template match="q">"<xsl:apply-templates/>"</xsl:template>
59
+ <xsl:template match="strike"><s><xsl:apply-templates/></s></xsl:template>
60
+ <xsl:template match="strong"><b><xsl:apply-templates/></b></xsl:template>
61
+
62
+ <!-- Block elements transformations -->
63
+ <xsl:template match="section"><div class="{@class}" style="{@style}"><xsl:apply-templates/></div></xsl:template>
64
+ <xsl:template match="article"><div class="{@class}" style="{@style}"><xsl:apply-templates/></div></xsl:template>
65
+
66
+ <xsl:template match="@*|node()">
67
+ <xsl:copy>
68
+ <xsl:apply-templates select="@*|node()"/>
69
+ </xsl:copy>
70
+ </xsl:template>
71
+ </xsl:stylesheet>