最近我开始在我的网站中使用 simpleMDE,但我在使用输入按钮将本地文本文件加载到我的 markdown 编辑器时遇到了问题。我也无法删除以前的数据并将其更改为“”。我使用烧瓶建立了我的网站,并且我正在使用烧瓶 simpleMDE 将 simpleMDE 加载到我的网站。我的代码:
你好.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Flask-SimpleMDE example</title>
{{ simplemde.css }}
{{ simplemde.js }}
</head>
<body>
<div>
<input type="file">
<textarea>
Some Markdown Text Here
</textarea>
</div>
<script>
let input = document.querySelector('input')
let textarea = document.querySelector('textarea')
// This event listener has been implemented to identify a
// Change in the input section of the html code
// It will be triggered when a file is chosen.
input.addEventListener('change', () => {
let files = input.files;
if (files.length == 0) return;
/* If any further modifications have to be made on the
Extracted text. The text can be accessed using the
file variable. But since this is const, it is a read
only variable, hence immutable. To make any changes,
changing const to var, here and In the reader.onload
function would be advisible */
const file = files[0];
let reader = new FileReader();
reader.onload = (e) => {
const file = e.target.result;
// This is a regular expression to identify carriage
// Returns and line breaks
const lines = file.split(/\r\n|\n/);
textarea.value = lines.join('\n');
};
reader.onerror = (e) => alert(e.target.error.name);
reader.readAsText(file);
});
var simplemde = new SimpleMDE({
autofocus: true,
autosave: {
enabled: true,
uniqueId: "MyUniqueID",
delay: 1000,
},
});
</script>
</body>
</html>
我的应用程序:
from flask import Flask, render_template,request
from flask_simplemde import SimpleMDE
app = Flask(__name__)
app.config['SIMPLEMDE_JS_IIFE'] = True
app.config['SIMPLEMDE_USE_CDN'] = True
SimpleMDE(app)
@app.route('/')
def hello():
return render_template('hello.html')
if __name__ == '__main__':
app.run(debug=True)
当我尝试在没有烧瓶的情况下运行文件时,我显然看不到simplemde
但看到 textarea 并且能够使用输入按钮将文本文件加载到其中,并且在运行烧瓶应用程序时我能够看到 simpleMDE 但无法将文本文件加载到其中。有什么建议吗?