Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
benbalter committed Mar 22, 2014
1 parent 39233d4 commit f891607
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/word-to-markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

class WordToMarkdown

attr_reader :doc
HEADING_DEPTH = 6
HEADING_DEPTH = 6 # Number of headings to guess, e.g., h6
HEADING_STEP = 100/HEADING_DEPTH
LI_SELECTORS = %w[
MsoListParagraphCxSpFirst
MsoListParagraphCxSpMiddle
MsoListParagraphCxSpLast
]

attr_reader :path
attr_accessor :html, :doc
attr_reader :path, :doc, :html

def initialize(path)
@path = path
Expand All @@ -39,6 +37,7 @@ def scrub_whitespace(string)
string
end

# Returns an array of Nokogiri nodes that are implicit headings
def implicit_headings
@implicit_headings ||= begin
headings = []
Expand All @@ -49,6 +48,7 @@ def implicit_headings
end
end

# Returns an array of font-sizes for implicit headings in the document
def font_sizes
@font_sizes ||= begin
sizes = []
Expand All @@ -57,6 +57,7 @@ def font_sizes
end
end

# Given a Nokogiri node, guess what heading it represents, if any
def guess_heading(node)
return nil if node.font_size == nil
[*1...HEADING_DEPTH].each do |heading|
Expand All @@ -65,6 +66,8 @@ def guess_heading(node)
nil
end

# Minimum font size required for a given heading
# e.g., H(2) would represent the minimum font size of an implicit h2
def h(n)
font_sizes.percentile ((HEADING_DEPTH-1)-n) * HEADING_STEP
end
Expand Down

0 comments on commit f891607

Please sign in to comment.