tex2wiki 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tex2wiki.gemspec
4
+ gemspec
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.
@@ -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
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -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)
@@ -0,0 +1,5 @@
1
+ require "tex2wiki/version"
2
+
3
+ module Tex2wiki
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Tex2wiki
2
+ VERSION = "0.0.1"
3
+ end
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!
@@ -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
@@ -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: []