I'll create a simple local site for managing tasks in markdown tables. Here's a complete solution with HTML, CSS, and Python backend:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Task Tables</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1000px;
margin: 0 auto;
padding: 20px;
}
.table-container {
margin-bottom: 30px;
border: 1px solid #ddd;
border-radius: 5px;
padding: 15px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 15px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.table-title {
font-size: 1.2em;
margin-bottom: 10px;
font-weight: bold;
}
.controls {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
button {
padding: 8px 12px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.add-row {
background-color: #2196F3;
}
.add-row:hover {
background-color: #0b7dda;
}
.copy-md {
background-color: #ff9800;
}
.copy-md:hover {
background-color: #e68a00;
}
.add-table {
display: block;
margin: 20px auto;
padding: 10px 15px;
font-size: 1.1em;
}
.new-table-form {
margin-top: 30px;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
display: none;
}
input[type="text"] {
padding: 8px;
width: 100%;
margin-bottom: 10px;
box-sizing: border-box;
}
.checkbox {
width: 20px;
height: 20px;
}
</style>
</head>
<body>
<h1>Markdown Task Tables</h1>
<div id="tables-container"></div>
<button id="show-add-table" class="add-table">+ ADD NEW TABLE</button>
<div id="new-table-form" class="new-table-form">
<h2>Create New Table</h2>
<input type="text" id="table-title" placeholder="Table Title">
<button id="create-table">Create Table</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
loadTables();
document.getElementById('show-add-table').addEventListener('click', function() {
document.getElementById('new-table-form').style.display = 'block';
});
document.getElementById('create-table').addEventListener('click', function() {
const title = document.getElementById('table-title').value.trim();
if (title) {
createNewTable(title);
document.getElementById('table-title').value = '';
document.getElementById('new-table-form').style.display = 'none';
}
});
});
function loadTables() {
fetch('/get_tables')
.then(response => response.json())
.then(data => {
const container = document.getElementById('tables-container');
container.innerHTML = '';
data.tables.forEach(table => {
const tableContainer = document.createElement('div');
tableContainer.className = 'table-container';
tableContainer.id = `table-${table.id}`;
const titleDiv = document.createElement('div');
titleDiv.className = 'table-title';
titleDiv.textContent = table.title;
tableContainer.appendChild(titleDiv);
const tableEl = document.createElement('table');
// Create header
const thead = document.createElement('thead');
const headerRow = document.createElement('tr');
const headers = ['Task', 'Status'];
headers.forEach(header => {
const th = document.createElement('th');
th.textContent = header;
headerRow.appendChild(th);
});
thead.appendChild(headerRow);
tableEl.appendChild(thead);
// Create body
const tbody = document.createElement('tbody');
table.tasks.forEach(task => {
const row = createTaskRow(task.name, task.done);
tbody.appendChild(row);
});
tableEl.appendChild(tbody);
tableContainer.appendChild(tableEl);
// Controls
const controls = document.createElement('div');
controls.className = 'controls';
const addRowBtn = document.createElement('button');
addRowBtn.className = 'add-row';
addRowBtn.textContent = '+ Add Task';
addRowBtn.addEventListener('click', function() {
const newRow = createTaskRow('', false);
tbody.appendChild(newRow);
});
const copyMdBtn = document.createElement('button');
copyMdBtn.className = 'copy-md';
copyMdBtn.textContent = 'Copy as Markdown';
copyMdBtn.addEventListener('click', function() {
copyTableAsMarkdown(table.id);
});
const saveBtn = document.createElement('button');
saveBtn.textContent = 'Save Changes';
saveBtn.addEventListener('click', function() {
saveTableChanges(table.id);
});
controls.appendChild(addRowBtn);
controls.appendChild(copyMdBtn);
controls.appendChild(saveBtn);
tableContainer.appendChild(controls);
container.appendChild(tableContainer);
});
})
.catch(error => console.error('Error loading tables:', error));
}
function createTaskRow(name, done) {
const row = document.createElement('tr');
const taskCell = document.createElement('td');
const taskInput = document.createElement('input');
taskInput.type = 'text';
taskInput.value = name;
taskInput.className = 'task-name';
taskCell.appendChild(taskInput);
const statusCell = document.createElement('td');
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.className = 'checkbox';
checkbox.checked = done;
statusCell.appendChild(checkbox);
row.appendChild(taskCell);
row.appendChild(statusCell);
return row;
}
function createNewTable(title) {
fetch('/create_table', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ title: title })
})
.then(response => response.json())
.then(data => {
if (data.success) {
loadTables();
}
})
.catch(error => console.error('Error creating table:', error));
}
function saveTableChanges(tableId) {
const tableContainer = document.getElementById(`table-${tableId}`);
const title = tableContainer.querySelector('.table-title').textContent;
const tasks = [];
const rows = tableContainer.querySelectorAll('tbody tr');
rows.forEach(row => {
const taskName = row.querySelector('.task-name').value.trim();
const isDone = row.querySelector('.checkbox').checked;
if (taskName) {
tasks.push({
name: taskName,
done: isDone
});
}
});
fetch('/update_table', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
id: tableId,
title: title,
tasks: tasks
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Table saved successfully!');
}
})
.catch(error => console.error('Error saving table:', error));
}
function copyTableAsMarkdown(tableId) {
fetch(`/get_table_markdown/${tableId}`)
.then(response => response.text())
.then(markdown => {
navigator.clipboard.writeText(markdown)
.then(() => alert('Markdown copied to clipboard!'))
.catch(err => console.error('Could not copy text: ', err));
})
.catch(error => console.error('Error getting markdown:', error));
}
</script>
</body>
</html>
from flask import Flask, request, jsonify, send_from_directory
import json
import os
import re
import uuid
app = Flask(__name__)
# File to store the tables data
DATA_FILE = 'tables.md'
# Initialize the data file if it doesn't exist
if not os.path.exists(DATA_FILE):
with open(DATA_FILE, 'w') as f:
f.write('# Task Tables\n\n')
def parse_markdown_tables():
"""Parse the markdown file and extract tables"""
tables = []
with open(DATA_FILE, 'r') as f:
content = f.read()
# Find table sections
table_sections = re.findall(r'## (.*?)\n\n\|(.*?)\n\|(.*?)\n((?:\|.*\n)*)', content, re.DOTALL)
for section in table_sections:
title = section[0]
table_id = re.search(r'id:(\S+)', title)
if table_id:
table_id = table_id.group(1)
title = re.sub(r'\s*id:\S+\s*', '', title).strip()
else:
table_id = str(uuid.uuid4())
tasks = []
rows = section[3].strip().split('\n')
for row in rows:
if row.strip():
columns = [col.strip() for col in row.split('|')[1:-1]]
if len(columns) >= 2:
task_name = columns[0]
status = columns[1].lower() == 'x' or columns[1].lower() == 'done'
tasks.append({'name': task_name, 'done': status})
tables.append({
'id': table_id,
'title': title,
'tasks': tasks
})
return tables
def save_tables_to_markdown(tables):
"""Save tables data to markdown file"""
content = '# Task Tables\n\n'
for table in tables:
content += f"## {table['title']} id:{table['id']}\n\n"
content += "| Task | Status |\n"
content += "| ---- | ------ |\n"
for task in table['tasks']:
status = 'X' if task['done'] else ' '
content += f"| {task['name']} | {status} |\n"
content += "\n"
with open(DATA_FILE, 'w') as f:
f.write(content)
def get_table_markdown(table_id):
"""Generate markdown for a specific table"""
tables = parse_markdown_tables()
for table in tables:
if table['id'] == table_id:
markdown = f"## {table['title']}\n\n"
markdown += "| Task | Status |\n"
markdown += "| ---- | ------ |\n"
for task in table['tasks']:
status = 'X' if task['done'] else ' '
markdown += f"| {task['name']} | {status} |\n"
return markdown
return ""
@app.route('/')
def index():
return send_from_directory('.', 'index.html')
@app.route('/get_tables')
def get_tables():
tables = parse_markdown_tables()
return jsonify({'tables': tables})
@app.route('/create_table', methods=['POST'])
def create_table():
data = request.json
title = data.get('title', 'Untitled Table')
tables = parse_markdown_tables()
new_table = {
'id': str(uuid.uuid4()),
'title': title,
'tasks': []
}
tables.append(new_table)
save_tables_to_markdown(tables)
return jsonify({'success': True, 'id': new_table['id']})
@app.route('/update_table', methods=['POST'])
def update_table():
data = request.json
table_id = data.get('id')
title = data.get('title')
tasks = data.get('tasks', [])
tables = parse_markdown_tables()
for i, table in enumerate(tables):
if table['id'] == table_id:
tables[i]['title'] = title
tables[i]['tasks'] = tasks
break
save_tables_to_markdown(tables)
return jsonify({'success': True})
@app.route('/get_table_markdown/<table_id>')
def get_markdown(table_id):
markdown = get_table_markdown(table_id)
return markdown
if __name__ == '__main__':
app.run(debug=True)
To use this:
- Save the HTML as
index.html
- Save the Python as
app.py
- Run the Python script:
python app.py
- Open your browser to
http://localhost:5000
The app lets you:
- Create new tables with the "+ ADD NEW TABLE" button
- Add tasks to tables with the "+ Add Task" button
- Mark tasks as done/not done with checkboxes
- Save changes to the markdown file
- Copy any table as markdown with the "Copy as Markdown" button
All tables are stored in a single tables.md file in the same directory.
Would you like me to explain or break down the code?