Skip to content

Commit

Permalink
cmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianguyen1234 committed Nov 14, 2024
1 parent 2e77763 commit 388e849
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
7 changes: 5 additions & 2 deletions app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ public function store(Request $request)
if ($existingSlugCount > 0) {
$slug .= '-' . ($existingSlugCount + 1);
}
// Clean the content using the custom configuration
$cleanContent = Purifier::clean($validated['content'], 'default');

// Set the post data
$postData = [
'title' => $validated['title'],
'slug' => $slug,
'content' => $validated['content'],
'content' => $cleanContent,
'youtube_iframe' => $validated['youtube_iframe'],
'meta_title' => $validated['meta_title'],
'meta_description' => $validated['meta_description'],
Expand Down Expand Up @@ -171,7 +173,8 @@ public function update(Request $request, $id)
}

// Clean the content and prepare post data
$cleanContent = Purifier::clean($validated['content']);
$cleanContent = Purifier::clean($validated['content'], 'default');

$postData = [
'title' => $validated['title'],
'slug' => $slug,
Expand Down
4 changes: 2 additions & 2 deletions config/purifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
'settings' => [
'default' => [
'HTML.Doctype' => 'HTML 4.01 Transitional',
'HTML.Allowed' => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]',
'HTML.Allowed' => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src],pre,code[class]',
'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
'AutoFormat.AutoParagraph' => true,
'AutoFormat.AutoParagraph' => false,
'AutoFormat.RemoveEmpty' => true,
],
'test' => [
Expand Down
25 changes: 11 additions & 14 deletions resources/views/layout.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down Expand Up @@ -121,7 +122,7 @@

<script>
document.addEventListener("DOMContentLoaded", function() {
// Markdown rendering using markdown-it
// Initialize markdown-it with HTML and syntax highlighting
var md = window.markdownit({
html: true,
highlight: function(str, lang) {
Expand All @@ -135,39 +136,35 @@
try {
return hljs.highlightAuto(str).value;
} catch (__) {}
return '';
return ''; // Default if no language detected
}
});
// Insert code block when "Add Code Block" button is clicked
// Add code block template at cursor position
document.getElementById('add-code-block').addEventListener('click', function() {
const contentArea = document.getElementById('content');
const codeTemplate = "```language\n// Paste your code here\n```";
// Insert code block at the cursor position
const codeTemplate = "```language\n// Your code here\n```";
const cursorPosition = contentArea.selectionStart;
const content = contentArea.value;
contentArea.value = content.slice(0, cursorPosition) + codeTemplate + content.slice(cursorPosition);
// Optionally, move cursor between the backticks for editing
contentArea.value = contentArea.value.slice(0, cursorPosition) + codeTemplate + contentArea.value.slice(cursorPosition);
contentArea.focus();
contentArea.setSelectionRange(cursorPosition + 3, cursorPosition + 11);
contentArea.setSelectionRange(cursorPosition + 3, cursorPosition + 11); // Position cursor in 'language' area
});
// Convert Markdown content to HTML when "Convert to HTML" button is clicked
// Convert Markdown to HTML and render in output area
document.getElementById('convert-button').addEventListener('click', function() {
const content = document.getElementById('content').value;
const htmlContent = md.render(content);
document.getElementById('render-here').innerHTML = htmlContent;
// Apply syntax highlighting to any code blocks
document.querySelectorAll('pre code').forEach((block) => {
// Apply syntax highlighting to code blocks
document.querySelectorAll('pre code').forEach(block => {
hljs.highlightElement(block);
});
});
});
</script>


@if(session('success'))
<script>
Swal.fire({
Expand Down

0 comments on commit 388e849

Please sign in to comment.