tex2wiki 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/tex2wiki +100 -0
- data/lib/tex2wiki.rb +5 -0
- data/lib/tex2wiki/version.rb +3 -0
- data/q.log +12 -0
- data/tex2wiki.gemspec +20 -0
- data/texput.log +11 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Francesco Sacchi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Tex2wiki
|
2
|
+
|
3
|
+
This gem converts a tex file to mediawiki and uploads its content to a mediawiki url
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tex2wiki'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tex2wiki
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/tex2wiki
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'nokogiri'
|
6
|
+
require "optparse"
|
7
|
+
require 'media_wiki'
|
8
|
+
options = {
|
9
|
+
:inputFile => '',
|
10
|
+
:wikiUrl => '',
|
11
|
+
:pageTitle => '',
|
12
|
+
:user => '',
|
13
|
+
:password => ''}
|
14
|
+
|
15
|
+
ARGV.options do |opts|
|
16
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] OTHER_ARGS"
|
17
|
+
|
18
|
+
opts.separator ""
|
19
|
+
opts.separator "Specific Options:"
|
20
|
+
|
21
|
+
opts.on( "-f File", "--input-file", String,
|
22
|
+
"File name for the input to process. if the file is not specified stdin will be used instead" ) do |opt|
|
23
|
+
options[:inputFile] = opt
|
24
|
+
end
|
25
|
+
opts.on( "-n Username", "--wiki-username", String,
|
26
|
+
"Username to access the wiki." ) do |opt|
|
27
|
+
options[:user] = opt
|
28
|
+
end
|
29
|
+
opts.on( "-p Password", "--wiki-password", String,
|
30
|
+
"Password to access the wiki." ) do |opt|
|
31
|
+
options[:password] = opt
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on( "-u Url", "--wiki-api-url", String,
|
35
|
+
"url to the wiki api.php file" ) do |opt|
|
36
|
+
options[:wikiUrl] = opt
|
37
|
+
|
38
|
+
end
|
39
|
+
opts.on( "-t Title", "--page-title", String,
|
40
|
+
"title of the wiki page. it can be of the form title#section. in this case the section section will be replaced by the specified file" ) do |opt|
|
41
|
+
options[:pageTitle] = opt
|
42
|
+
|
43
|
+
end
|
44
|
+
opts.separator "Common Options:"
|
45
|
+
|
46
|
+
opts.on( "-h", "--help",
|
47
|
+
"Show this message." ) do
|
48
|
+
puts opts
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
begin
|
53
|
+
opts.parse!
|
54
|
+
rescue
|
55
|
+
puts opts
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
# tex = ""
|
60
|
+
# if options[:inputFile] == ''
|
61
|
+
# puts 'reading from stdin'
|
62
|
+
# while a = gets
|
63
|
+
# tex << a
|
64
|
+
# end
|
65
|
+
|
66
|
+
# puts tex
|
67
|
+
# else
|
68
|
+
# tex = File.open(options[:inputFile], "r").read
|
69
|
+
# end
|
70
|
+
tex = File.open(options[:inputFile], "r").read
|
71
|
+
|
72
|
+
|
73
|
+
params = {'fromFormat'=>'LaTeX','toFormat'=>'MediaWiki','textToConvert'=>tex}
|
74
|
+
postData = Net::HTTP.post_form(URI.parse('http://johnmacfarlane.net/pandoc/try'), params)
|
75
|
+
page = Nokogiri::HTML(postData.body)
|
76
|
+
|
77
|
+
mediawiki = page.css('pre').first.content
|
78
|
+
|
79
|
+
mw = MediaWiki::Gateway.new(options[:wikiUrl])
|
80
|
+
|
81
|
+
content = ""
|
82
|
+
if options[:pageTitle].index('#')
|
83
|
+
section = options[:pageTitle][options[:pageTitle].index('#')+1..-1]
|
84
|
+
options[:pageTitle] = options[:pageTitle][0...options[:pageTitle].index('#')]
|
85
|
+
content = mw.get(options[:pageTitle])
|
86
|
+
# need to parse the content to replace the specified section with the new one
|
87
|
+
section_start_index = content.index(/(=+) *#{section} *\1/)
|
88
|
+
section_level = content[section_start_index..section_start_index+20].index(/[^=]/)
|
89
|
+
end_title_index = section_start_index+content[section_start_index+section_level..-1].index('=')+section_level*2
|
90
|
+
section_end_index = content.index(/={1,#{section_level}}[^=]/,end_title_index) || content.length+1
|
91
|
+
mediawiki.gsub!(/(=+)/,"\\1#{'='*(section_level-1)}")
|
92
|
+
content[section_start_index...section_end_index]=mediawiki
|
93
|
+
|
94
|
+
else
|
95
|
+
content = mediawiki
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
mw.login(options[:user],options[:password])
|
100
|
+
mw.edit(options[:pageTitle], content)
|
data/lib/tex2wiki.rb
ADDED
data/q.log
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=pdftex 2011.11.1) 22 AUG 2012 20:27
|
2
|
+
entering extended mode
|
3
|
+
%&-line parsing enabled.
|
4
|
+
**q
|
5
|
+
(/usr/share/texmf-texlive/tex/latex/tools/q.tex File ignored
|
6
|
+
)
|
7
|
+
! Emergency stop.
|
8
|
+
<*> q
|
9
|
+
|
10
|
+
*** (job aborted, no legal \end found)
|
11
|
+
|
12
|
+
! ==> Fatal error occurred, no output PDF file produced!
|
data/tex2wiki.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/tex2wiki/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Francesco Sacchi"]
|
6
|
+
gem.email = ["depsir@gmail.com"]
|
7
|
+
gem.description = %q{This gem converts a tex file to mediawiki and uploads its content to a mediawiki url}
|
8
|
+
gem.summary = %q{This gem converts a tex file to mediawiki and uploads its content to a mediawiki url}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "tex2wiki"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Tex2wiki::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'nokogiri'
|
19
|
+
gem.add_runtime_dependency 'mediawiki-gateway'
|
20
|
+
end
|
data/texput.log
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=etex 2011.11.1) 22 AUG 2012 20:27
|
2
|
+
entering extended mode
|
3
|
+
%&-line parsing enabled.
|
4
|
+
**merge
|
5
|
+
|
6
|
+
! Emergency stop.
|
7
|
+
<*> merge
|
8
|
+
|
9
|
+
End of file on the terminal!
|
10
|
+
|
11
|
+
No pages of output.
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tex2wiki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Francesco Sacchi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mediawiki-gateway
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: This gem converts a tex file to mediawiki and uploads its content to
|
47
|
+
a mediawiki url
|
48
|
+
email:
|
49
|
+
- depsir@gmail.com
|
50
|
+
executables:
|
51
|
+
- tex2wiki
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/tex2wiki
|
61
|
+
- lib/tex2wiki.rb
|
62
|
+
- lib/tex2wiki/version.rb
|
63
|
+
- q.log
|
64
|
+
- tex2wiki.gemspec
|
65
|
+
- texput.log
|
66
|
+
homepage: ''
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.19
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: This gem converts a tex file to mediawiki and uploads its content to a mediawiki
|
90
|
+
url
|
91
|
+
test_files: []
|