This repository was archived by the owner on Nov 8, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork20
feat(editor-export): table block#288
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
d2d1d0d
refactor(editor): basic table export done
mydearxymc6ac24c
refactor(editor): table header & strip export done
mydearxym2e16b16
refactor(editor): spec-types && add more tests
mydearxym35ccc07
fix(editor-export): table test warnings
mydearxym51e7afc
fix(editor-export): table test warnings
mydearxymFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletionslib/helper/converter/editor_to_html/class.ex
This file contains hidden or 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
62 changes: 62 additions & 0 deletionslib/helper/converter/editor_to_html/frags/table.ex
This file contains hidden or 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,62 @@ | ||
defmodule Helper.Converter.EditorToHTML.Frags.Table do | ||
@moduledoc """ | ||
parse editor.js's block fragments, use for test too | ||
see https://editorjs.io/ | ||
""" | ||
alias Helper.Converter.EditorToHTML.Class | ||
alias Helper.Types, as: T | ||
@class get_in(Class.article(), ["table"]) | ||
@spec get_row([T.editor_table_cell()]) :: T.html() | ||
def get_row(group_items) do | ||
tr_content = | ||
Enum.reduce(group_items, "", fn item, acc -> | ||
cell_type = if Map.has_key?(item, "isHeader"), do: :th, else: :td | ||
acc <> frag(cell_type, item) | ||
end) | ||
~s(<tr>#{tr_content}</tr>) | ||
end | ||
@spec frag(:td, T.editor_table_cell()) :: T.html() | ||
def frag(:td, item) do | ||
%{ | ||
"align" => align, | ||
"isStripe" => is_stripe, | ||
"text" => text | ||
} = item | ||
cell_class = @class["cell"] | ||
align_class = get_align_class(align) | ||
scripe_class = if is_stripe, do: @class["td_stripe"], else: "" | ||
case Map.has_key?(item, "width") do | ||
true -> | ||
style = ~s(width: #{Map.get(item, "width")}) | ||
~s(<td class="#{scripe_class}" style="#{style}"><div class="#{cell_class} #{align_class}">#{ | ||
text | ||
}</div></td>) | ||
false -> | ||
~s(<td class="#{scripe_class}"><div class="#{cell_class} #{align_class}">#{text}</div></td>) | ||
end | ||
end | ||
@spec frag(:th, T.editor_table_cell()) :: T.html() | ||
def frag(:th, item) do | ||
%{"align" => align, "text" => text} = item | ||
cell_class = @class["cell"] | ||
align_class = get_align_class(align) | ||
header_class = @class["th_header"] | ||
~s(<th class="#{header_class}"><div class="#{cell_class} #{align_class}">#{text}</div></th>) | ||
end | ||
defp get_align_class("center"), do: @class["align_center"] | ||
defp get_align_class("right"), do: @class["align_right"] | ||
defp get_align_class(_), do: @class["align_left"] | ||
end |
9 changes: 6 additions & 3 deletionslib/helper/converter/editor_to_html/frontend_test/script.js
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
73 changes: 73 additions & 0 deletionslib/helper/converter/editor_to_html/frontend_test/styles.css
This file contains hidden or 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
23 changes: 23 additions & 0 deletionslib/helper/converter/editor_to_html/index.ex
This file contains hidden or 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
16 changes: 16 additions & 0 deletionslib/helper/converter/editor_to_html/validator/editor_schema.ex
This file contains hidden or 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
10 changes: 7 additions & 3 deletionslib/helper/converter/editor_to_html/validator/index.ex
This file contains hidden or 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
7 changes: 7 additions & 0 deletionslib/helper/converter/html_sanitizer.ex
This file contains hidden or 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
16 changes: 16 additions & 0 deletionslib/helper/types.ex
This file contains hidden or 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
4 changes: 2 additions & 2 deletionstest/helper/converter/editor_to_html_test/header_test.exs
This file contains hidden or 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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.