-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 80e8d0d
Showing
20 changed files
with
945 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea | ||
config.json | ||
gen_docs_final/* | ||
gen_docs_raw/* | ||
gen_images/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
readme-converter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source 'https://rubygems.org' | ||
gem 'faraday' | ||
gem 'pry' | ||
gem 'rspec' | ||
gem 'kramdown' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
coderay (1.1.3) | ||
diff-lcs (1.4.4) | ||
faraday (1.1.0) | ||
multipart-post (>= 1.2, < 3) | ||
ruby2_keywords | ||
kramdown (2.3.0) | ||
rexml | ||
method_source (1.0.0) | ||
multipart-post (2.1.1) | ||
pry (0.13.1) | ||
coderay (~> 1.1) | ||
method_source (~> 1.0) | ||
rexml (3.2.4) | ||
rspec (3.9.0) | ||
rspec-core (~> 3.9.0) | ||
rspec-expectations (~> 3.9.0) | ||
rspec-mocks (~> 3.9.0) | ||
rspec-core (3.9.3) | ||
rspec-support (~> 3.9.3) | ||
rspec-expectations (3.9.3) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.9.0) | ||
rspec-mocks (3.9.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.9.0) | ||
rspec-support (3.9.4) | ||
ruby2_keywords (0.0.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
faraday | ||
kramdown | ||
pry | ||
rspec | ||
|
||
BUNDLED WITH | ||
1.17.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Export Script for Readme.com | ||
|
||
This little script exports data from a readme.com (readme.io) documentation site into respective markdown. | ||
|
||
What it does: | ||
|
||
* Export pages into markdown | ||
* Download images from readme.com | ||
|
||
What it doesn't do yet: | ||
|
||
* Get list of pages in your site | ||
* Get the navigation structure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"README_APIKEY": "your apikey here", | ||
"IMAGE_PATH_PREFIX": "https://cdn.holistics.io/docs/readme/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
class ApiHeaderBlockReplacer | ||
attr_accessor :block_string | ||
|
||
def initialize(block_string) | ||
self.block_string = block_string | ||
end | ||
|
||
def get_markdown() | ||
json_string = block_string.strip[18..-9] | ||
h = JSON.parse(json_string) | ||
|
||
"# #{h['title']}" | ||
end | ||
|
||
def self.scan(body) | ||
body.gsub /\[block:api-header\](.+?)\[\/block\]/m do |str| | ||
puts "Found API Header block ..." | ||
ApiHeaderBlockReplacer.new(str).get_markdown | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
class CalloutBlockReplacer | ||
attr_accessor :block_string | ||
|
||
def initialize(block_string) | ||
self.block_string = block_string | ||
end | ||
|
||
def get_markdown() | ||
json_string = block_string.strip[15..-9] | ||
h = JSON.parse(json_string) | ||
type = h['type'] | ||
title = (h['title'] ? " #{h['title']}" : nil) | ||
body = h['body'] | ||
|
||
<<~MARKDOWN | ||
:::#{type}#{title} | ||
#{body} | ||
::: | ||
MARKDOWN | ||
end | ||
|
||
def self.scan(body) | ||
body.gsub /\[block:callout\](.+?)\[\/block\]/m do |str| | ||
puts "Found Callout block ..." | ||
CalloutBlockReplacer.new(str).get_markdown | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
class CodeBlockReplacer | ||
attr_accessor :block_string | ||
|
||
def initialize(block_string) | ||
self.block_string = block_string | ||
end | ||
|
||
def get_markdown() | ||
json_string = block_string.strip[12..-9] | ||
h = JSON.parse(json_string) | ||
|
||
markdowns = h['codes'].map do |item| | ||
code = item['code'] | ||
language = item['language'] | ||
puts " Language: #{language}" | ||
|
||
<<-MARKDOWN | ||
```#{language} | ||
#{code} | ||
``` | ||
MARKDOWN | ||
end | ||
markdowns.join("\n") | ||
end | ||
|
||
def self.scan(body) | ||
body.gsub /\[block:code\](.+?)\[\/block\]/m do |str| | ||
puts "Found code block ..." | ||
CodeBlockReplacer.new(str).get_markdown | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
class EmbedBlockReplacer | ||
attr_accessor :block_string | ||
|
||
def initialize(block_string) | ||
self.block_string = block_string | ||
end | ||
|
||
def get_markdown() | ||
json_string = block_string.strip[13..-9] | ||
h = JSON.parse(json_string) | ||
|
||
<<~HTML | ||
<iframe src="#{h['url']}"></iframe> | ||
HTML | ||
end | ||
|
||
def self.scan(body) | ||
body.gsub /\[block:embed\](.+?)\[\/block\]/m do |str| | ||
puts "Found embed block ..." | ||
EmbedBlockReplacer.new(str).get_markdown | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
class HtmlBlockReplacer | ||
attr_accessor :block_string | ||
|
||
def initialize(block_string) | ||
self.block_string = block_string | ||
end | ||
|
||
def get_markdown() | ||
json_string = block_string.strip[12..-9] | ||
h = JSON.parse(json_string) | ||
h['html'] | ||
end | ||
|
||
def self.scan(body) | ||
body.gsub /\[block:html\](.+?)\[\/block\]/m do |str| | ||
puts "Found HTML block ..." | ||
HtmlBlockReplacer.new(str).get_markdown | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
class ImageBlockReplacer | ||
attr_accessor :readme_block, :image_path_prefix | ||
|
||
def download_image(url) | ||
uri = URI.parse(url) | ||
filename = File.basename(uri.path) | ||
|
||
r = Faraday.get(url) | ||
if r.status != 200 | ||
puts "Error: #{response.status} - #{JSON.parse(response.body)['message']}" | ||
return | ||
end | ||
|
||
dest_filepath = "./gen_images/#{filename}" | ||
File.open(dest_filepath, 'wb') {|f| f.write(r.body)} | ||
filename | ||
end | ||
|
||
def initialize(readme_block, image_path_prefix: nil) | ||
self.readme_block = readme_block | ||
self.image_path_prefix = image_path_prefix | ||
end | ||
|
||
def get_markdown() | ||
h = JSON.parse(readme_block.strip[13..-9]) | ||
|
||
markdowns = h['images'].map do |image| | ||
url = image['image'].first | ||
return '' if url.nil? | ||
|
||
puts "Downloading image #{url} ..." | ||
filename = download_image(url) | ||
|
||
cdn_filepath = "#{self.image_path_prefix}#{filename}" | ||
|
||
"\n\n" | ||
end | ||
markdowns.join("\n") | ||
end | ||
|
||
def self.scan(body, image_path_prefix: '/images/') | ||
body.gsub /\[block:image\](.+?)\[\/block\]/m do |str| | ||
puts "Found image block ..." | ||
ImageBlockReplacer.new(str, image_path_prefix: image_path_prefix).get_markdown | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
class InternalHrefReplacer | ||
|
||
def self.scan(body) | ||
body.gsub /\(doc:([^)]+)\)/ do | ||
v = Regexp.last_match[1] | ||
parts = v.split('#') | ||
anchor = (parts[1].nil? ? '' : "##{parts[1]}") | ||
"(" + parts[0] + ".md" + anchor + ")" | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'kramdown' | ||
|
||
class ParametersBlockReplacer | ||
attr_accessor :block_string | ||
|
||
def initialize(block_string) | ||
self.block_string = block_string | ||
end | ||
|
||
def get_markdown() | ||
json_string = block_string.strip[18..-9] | ||
h = JSON.parse(json_string) | ||
cols = h['cols'].to_i | ||
rows = h['rows'].to_i | ||
data = h['data'] | ||
|
||
headers = (0..cols-1).to_a.map do |i| | ||
data["h-#{i}"] | ||
end | ||
records = (0 .. rows-1).to_a.map do |i| | ||
(0..cols-1).to_a.map do |j| | ||
data["#{i}-#{j}"] | ||
end | ||
end | ||
|
||
headers_html = headers.map do |item| | ||
"<th>#{item}</th>" | ||
end.join("\n") | ||
|
||
records_html = records.map do |row| | ||
"<tr>" + | ||
row.map do |cell| | ||
html = Kramdown::Document.new(cell.to_s).to_html | ||
"<td>#{html}</td>" | ||
end.join("\n") + | ||
"</tr>" | ||
end.join("\n") | ||
|
||
<<~HTML | ||
<table> | ||
<thead> | ||
#{headers_html} | ||
</thead> | ||
<tbody> | ||
#{records_html} | ||
</tbody> | ||
</table> | ||
HTML | ||
end | ||
|
||
def self.scan(body) | ||
body.gsub /\[block:parameters\](.+?)\[\/block\]/m do |str| | ||
puts "Found parameters block ..." | ||
ParametersBlockReplacer.new(str).get_markdown | ||
end | ||
end | ||
end | ||
|
Oops, something went wrong.