Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

feat(editor-export): image block workflow#298

Merged
mydearxym merged 5 commits intodevfromeditor-image
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletionslib/helper/converter/editor_to_html/class.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,6 +61,25 @@ defmodule Helper.Converter.EditorToHTML.Class do
"align_center" => "align-center",
"align_left" => "align-left",
"align_right" => "align-right"
},
"image" => %{
"wrapper" => "image-wrapper",
"single_image_wrapper" => "single-image",
"single_image" => "image-picture",
"image_caption" => "image-caption",
# "single_caption"
# jiugongge
"jiugongge_image_wrapper" => "jiugongge-image",
"jiugongge_image_block" => "jiugongge-block",
"jiugongge_image" => "jiugongge-block-image",
# gallery
"gallery_image_wrapper" => "gallery-image",
"gallery_image_inner" => "gallery-image-inner",
"gallery_image_block" => "gallery-block",
"gallery_image" => "gallery-block-image",
# minimap
"gallery_minimap" => "gallery-minimap",
"gallery_minimap_image" => "gallery-minimap-block-image"
}
}
end
Expand Down
124 changes: 124 additions & 0 deletionslib/helper/converter/editor_to_html/frags/image.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
defmodule Helper.Converter.EditorToHTML.Frags.Image do
@moduledoc """
parse editor.js's block fragments, use for test too

see https://editorjs.io/
"""
import Helper.Validator.Guards, only: [g_none_empty_str: 1]

alias Helper.Converter.EditorToHTML.Class
alias Helper.Types, as: T

@class get_in(Class.article(), ["image"])

@spec get_item(:single | :gallery | :jiugongge, T.editor_image_item()) :: T.html()
def get_item(
:single,
%{
"src" => src,
"width" => width,
"height" => height
} = data
)
when g_none_empty_str(width) and g_none_empty_str(height) do
caption = get_caption(data)

image_wrapper_class = @class["single_image_wrapper"]
image_class = @class["single_image"]

~s(<div class="#{image_wrapper_class}">
<a href=#{src} class="glightbox" data-glightbox="type:image;description: #{caption}">
<img class="#{image_class}" style="width:#{width}; height:#{height}" src="#{src}" alt="image" />
</a>
</div>)
end

def get_item(:single, %{"src" => src} = data) do
caption = get_caption(data)

image_wrapper_class = @class["single_image_wrapper"]
image_class = @class["single_image"]

~s(<div class="#{image_wrapper_class}">
<a href=#{src} class="glightbox" data-glightbox="type:image;description: #{caption}">
<img class="#{image_class}" src="#{src}" alt="image" />
</a>
</div>)
end

def get_item(:jiugongge, %{"src" => src} = data) do
caption = get_caption(data)
# image_wrapper_class = @class["jiugongge-image"]

jiugongge_image_block_class = @class["jiugongge_image_block"]
image_class = @class["jiugongge_image"]

~s(<div class="#{jiugongge_image_block_class}">
<a href=#{src} class="glightbox" data-glightbox="type:image;description: #{caption}">
<img class="#{image_class}" src="#{src}" alt="image" />
</a>
</div>)
end

def get_item(:gallery, %{"src" => src, "index" => index} = data) do
caption = get_caption(data)

gallery_image_block_class = @class["gallery_image_block"]
image_class = @class["gallery_image"]

# IO.inspect(index, label: "index -> ")
~s(<div class="#{gallery_image_block_class}">
<a href=#{src} class="glightbox" data-glightbox="type:image;description: #{caption}">
<img class="#{image_class}" src="#{src}" alt="image" data-index="#{index}" />
</a>
</div>)
end

@spec get_minimap([T.editor_image_item()]) :: T.html()
def get_minimap(items) do
wrapper_class = @class["gallery_minimap"]

items_content =
Enum.reduce(items, "", fn item, acc ->
acc <> frag(:minimap_image, item)
end)

~s(<div class="#{wrapper_class}">
#{items_content}
</div>)
end

defp frag(:minimap_image, %{"src" => src, "index" => index}) do
image_class = @class["gallery_minimap_image"]

~s(<img class="#{image_class}" src="#{src}" data-index="#{index}"/>)
end

def get_caption(%{"caption" => caption}) when g_none_empty_str(caption), do: caption
def get_caption(_), do: ""

def get_caption(:html, %{"caption" => caption}) when g_none_empty_str(caption) do
image_caption = @class["image_caption"]
~s(<div class="#{image_caption}">#{caption}</div>)
end

def get_caption(:html, _), do: ""

# @spec frag(:checkbox, :text, String.t()) :: T.html()
# def frag(:checkbox, :text, text) do
# text_class = @class["checklist_text"]

# ~s(<div class="#{text_class}">
# #{text}
# </div>)
# end

# defp svg(type) do
# # workarround for https://github.com/rrrene/html_sanitize_ex/issues/48
# svg_frag(type) |> String.replace(" viewBox=\"", " viewbox=\"")
# end

# defp svg_frag(:checked) do
# ~s(<svg t="1592049095081" width="20px" height="20px" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9783"><path d="M853.333333 256L384 725.333333l-213.333333-213.333333" p-id="9784"></path></svg>)
# end
end
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,11 +8,13 @@
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css" />
<link rel="stylesheet" href="./styles.css?v=1.0">
<div id="article"></div>
</head>

<body>
<script src="https://cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js"></script>
<script src="./script.js"></script>
</body>
</html>
42 changes: 39 additions & 3 deletionslib/helper/converter/editor_to_html/frontend_test/script.js
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

138 changes: 136 additions & 2 deletionslib/helper/converter/editor_to_html/frontend_test/styles.css
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
body {
border: 1px solid #ececec;
min-height: 80vh;
margin: 20px 5vw;
display: flex;
justify-content: center;
}

#article {
width: 650px;
border: 1px solid #ececec;
}

.glightbox-clean .gslide-description {
background: transparent !important;
}
.gdesc-inner {
background-image: linear-gradient(transparent, #272727) !important;
color: lightgrey;
font-size: 15px;
position: absolute;
width: calc(100% - 39px);
bottom: 0;
left: -1px;
word-break: break-all;
}

.article-viewer-wrapper {
Expand DownExpand Up@@ -366,3 +385,118 @@ td {
}

/* quote block end */

/* image block */
.article-viewer-wrapper .image-wrapper {
position: relative;
margin-top: 20px;
margin-bottom: 20px;
}

.article-viewer-wrapper .image-wrapper .single-image {
display: flex;
justify-content: center;
width: 100%;
height: 100%;
}

.article-viewer-wrapper .image-wrapper .single-image .image-picture {
max-width: 100%;
display: block;
z-index: 5;
}

.article-viewer-wrapper .image-wrapper .image-caption {
text-align: center;
color: grey;
margin-top: 15px;
}

.article-viewer-wrapper .image-wrapper .jiugongge-image {
display: flex;
flex-wrap: wrap;
width: 489px;
max-height: 489px;
margin: 0 auto;
padding: 45px 0;
}

.article-viewer-wrapper .image-wrapper .jiugongge-block {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 160px;
height: 160px;
border-radius: 2px;
background: #efefef;
margin-right: 3px;
margin-bottom: 3px;
}

.article-viewer-wrapper .image-wrapper a {
width: 100%;
height: 100%;
}

.article-viewer-wrapper .image-wrapper .jiugongge-block-image {
width: 100%;
height: 100%;
object-fit: cover;
transition: all 0.25s;
}

.article-viewer-wrapper .image-wrapper .gallery-image {
width: 100%;
max-height: 400px;
overflow: hidden;
}

.article-viewer-wrapper .image-wrapper .gallery-image-inner {
display: flex;
width: 100%;
max-height: 400px;
padding-bottom: 17px;
overflow: scroll;
}

.article-viewer-wrapper .image-wrapper .gallery-block {
position: relative;
border-radius: 2px;
background: #efefef;
margin-right: 5px;
margin-bottom: 3px;
width: auto;
}

.article-viewer-wrapper .image-wrapper a {
width: 100%;
height: 100%;
}

.article-viewer-wrapper .image-wrapper .gallery-block-image {
width: auto;
height: 400px;
object-fit: cover;
transition: all 0.25s;
}

.article-viewer-wrapper .image-wrapper .gallery-minimap {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 55px;
margin-top: 6px;
}

.article-viewer-wrapper .image-wrapper .gallery-minimap-block-image {
width: 46px;
height: 46px;
margin-right: 6px;
object-fit: contain;
background: #f7f7f7;
cursor: pointer;
}

/* image block end */
Loading

[8]ページ先頭

©2009-2025 Movatter.jp