forked from cjberg/confluence-to-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page.coffee
73 lines (59 loc) · 2.33 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
61
62
63
64
65
66
67
68
69
70
71
72
73
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.removeAttachmentsSection content
content = @formatter.removeRecipeTable content
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.fixAttachmentWrapper content
content = @formatter.fixPageLog content
content = @formatter.wrapCodeBlocks content
content = @formatter.removeApScriptElements content
content = @formatter.removeStyleTags content
content = @formatter.fixLocalLinks content, @space, pages
if @fileName == 'index.html'
content = @formatter.fixDuplicateUnorderedListSiblings content
@formatter.getHtml content
###*
# Converts HTML file at given path to MD formatted text without removing any elements.
# @return {string} Content of a file parsed to MD
###
getRawText: (pages) ->
content = @formatter.getPageMeta @content, @fileName
@formatter.getHtml content
module.exports = Page