我正在创建一个自定义元素,它将能够将其内容从 Markdown 转换为 HTML。但是,我无法获取自定义元素的内容。
<!doctype html>
<html>
<body>
<template id="mark-down">
<div class="markdown"></div>
</template>
<!-- Converts markdown to HTML -->
<script src="https://cdn.jsdelivr.net/gh/showdownjs/showdown/dist/showdown.js"></script>
<script>
customElements.define('mark-down',
class extends HTMLElement {
constructor() {
super()
let template = document.querySelector('#mark-down').content
this.attachShadow({ mode: 'open' }).appendChild(template.cloneNode(true))
}
connectedCallback() {
console.log(this) // Returns the whole <mark-down> node and its contents
console.log(this.innerHTML) // So why does this return a blank string?
// This should theoretically work --> let markdown = this.innerHTML
let markdown = '## Test'
let converter …Run Code Online (Sandbox Code Playgroud)我正在尝试列出首页上某个部分的页面。这应该不会太难;例如,具有以下层次结构(名称通用):
/content/
|_ test-page.md
|_ /section-name/
|_ page1.md
|_ page2.md
Run Code Online (Sandbox Code Playgroud)
使用以下循环:
{{ range .Pages }}
...
{{ end }}
Run Code Online (Sandbox Code Playgroud)
/section-name/给出as的列表页"section-names"。
好吧,我在网上寻找其他解决方案。例如:
{{ range first 5 (where .Data.Pages "Section" "in" (slice "section-name")) }}
Run Code Online (Sandbox Code Playgroud)
但这仍然返回"section-names"。
好的,文档中有 where 子句和分组的示例。例如,{{ range (.Pages.GroupBy "Section").Reverse }}。让我们尝试一个类似的概念:
{{ range (.Pages.GroupBy "Section") }}
{{ .Key }}
{{ range .Pages }}
{{ .Title }}
{{ end }}
{{ end }}
Run Code Online (Sandbox Code Playgroud)
这似乎会打印每个键,然后打印该键下的每一页。然而,它打印的section-name Section-names不是我所希望的,section-name page1 page2.
什么?
另外,使用像 …
我想在单击时为图像制作动画以填充整个屏幕,以这样的方式从其原始位置无缝过渡到其完整尺寸,然后再返回,就像在 Medium 上一样。
这里的问题是 CSSposition属性 和top是left不可动画的。尝试之后,我想到使用transform: scale()属性,但这会导致一堆计算,我希望尽可能避免这些计算。
我的复杂解决方案是使用 获取元素的原始位置getBoundingClientRect(),然后从那里找到图像必须位于的结束位置,并在每次使用 将图像放大到完整尺寸时创建自定义动画Element.animate。我不确定这是解决这个问题的最佳方法,因为计算出图像的最终大小和位置将是一些我不想搞乱的额外数学。
下面是我当前的标记和一些 CSS,显示可以使用translateX()和为位置动画设置关键帧translateY(),但不是我真正需要的那样。
document.querySelector('picture').onclick = function () {
document.querySelector('picture').classList.toggle('modal')
}Run Code Online (Sandbox Code Playgroud)
<style>
figure {
margin: 0 0 0 0;
display: inline-block; /* Stays same width as image contents */
background-color: whitesmoke;
}
img {
max-width: 100%; /* Images should fit within their container by default */
height: auto;
background-color: lightgrey;
margin: auto;
} …Run Code Online (Sandbox Code Playgroud)我正在 Visual Studio 2017 中使用 Xamarin 和 C# 制作跨平台测验应用程序。这行代码出现问题:
DateTime today = new DateTime.Now;
Run Code Online (Sandbox Code Playgroud)
Visual Studio 强调.Now并声称“类型名称 'Now' 不存在于类型 'DateTime' 中。”
代码的目标是获取系统时间并将其显示在文本框中(以及为 notecard 构造函数创建日期)。由于.Now,Visual Studio 声明“类型名称 'Now' 不存在于类型 'DateTime' 中。
我也尝试使用System.DateTime.Now,但这并没有产生更好的结果,因为标题已经包含System. 下面是模板,它是 XAML 页面的标准 C#:
namespace DenisQuiz.UWP
{
// This page allows the user to create a new study set.
public sealed partial class CreateNewStudySet : Page
{
DateTime today = new DateTime.Now;
public CreateNewStudySet()
{
this.InitializeComponent();
automaticTodaysDate.Text = today.ToString();
}
} …Run Code Online (Sandbox Code Playgroud) 下面一行会...
var isAuthorized = (await _authorizationService.AuthorizeAsync(...)).Succeeded;
Run Code Online (Sandbox Code Playgroud)
...导致异步执行,在AuthorizeAsync(...)找到结果之前与调用者不同,还是会阻塞线程直到找到结果?为什么或者为什么不?
根据vb.net 的这个问题,这样的表达式被称为非文字。根据Fluently Calling Await without Parentheses和How to Design Fluent Async Operations 的问题和答案,这个说法似乎没问题。但是,我想确定并从文档中了解原因,使这种特殊情况变得清晰。