forked from meridius/confluence-to-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPage.coffee
60 lines (46 loc) · 1.76 KB
/
Page.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Page
constructor: (fullPath, @formatter, @utils) ->
@path = fullPath
@init()
init: () ->
@fileName = @utils.getBasename @path
@fileBaseName = @utils.getBasename @path, '.html'
@filePlainText = @utils.readFile @path
@$ = @formatter.load @filePlainText
@content = @$.root()
@heading = @getHeading()
@fileNameNew = @getFileNameNew()
@space = @utils.getBasename @utils.getDirname @path
@spacePath = @getSpacePath()
getSpacePath: () ->
'../' + @utils.sanitizeFilename(@space) + '/' + @fileNameNew
getFileNameNew: () ->
return 'index.md' if @fileName == 'index.html'
@utils.sanitizeFilename(@heading) + '.md'
getHeading: () ->
title = @content.find('title').text()
if @fileName == 'index.html'
title
else
indexName = @content.find('#breadcrumbs .first').text().trim()
title.replace indexName + ' : ', ''
###*
# Converts HTML file at given path to MD formatted text.
# @return {string} Content of a file parsed to MD
###
getTextToConvert: (pages) ->
content = @formatter.getRightContentByFileName @content, @fileName
content = @formatter.fixHeadline content
content = @formatter.fixIcon content
content = @formatter.fixEmptyLink content
content = @formatter.fixEmptyHeading content
content = @formatter.fixPreformattedText content
content = @formatter.fixImageWithinSpan content
content = @formatter.removeArbitraryElements content
content = @formatter.fixArbitraryClasses content
content = @formatter.fixAttachmentWraper content
content = @formatter.fixPageLog content
content = @formatter.fixLocalLinks content, @space, pages
content = @formatter.addPageHeading content, @heading
@formatter.getHtml content
module.exports = Page