From 9f23693e747d042b375c45aef9988e700ae8e29b Mon Sep 17 00:00:00 2001 From: Dimitris Spachos Date: Fri, 20 Dec 2024 09:08:06 +0200 Subject: [PATCH] fix(slb-495): eslint converter fix(slb-495): minor updates --- apps/converter/htmlToMarkdown.js | 6 +- apps/converter/jinaAi.js | 3 +- apps/converter/pdfToMarkdown.js | 3 +- apps/converter/utils/utils.js | 60 +++++++++---------- .../silverback_ai_import.module | 2 +- .../src/ContentImportAiService.php | 4 +- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/apps/converter/htmlToMarkdown.js b/apps/converter/htmlToMarkdown.js index 623156a2..fb5e544c 100644 --- a/apps/converter/htmlToMarkdown.js +++ b/apps/converter/htmlToMarkdown.js @@ -9,7 +9,11 @@ import fetch from 'node-fetch'; import path from 'path'; import { fileURLToPath } from 'url'; -import { convertToMarkdown,generateFolderName,validateAndFixMarkdown } from './utils/utils.js'; +import { + convertToMarkdown, + generateFolderName, + validateAndFixMarkdown, +} from './utils/utils.js'; /** * Extracts images from markdown content while preserving their positions diff --git a/apps/converter/jinaAi.js b/apps/converter/jinaAi.js index a990e62f..371d9d22 100644 --- a/apps/converter/jinaAi.js +++ b/apps/converter/jinaAi.js @@ -5,7 +5,7 @@ import fetch from 'node-fetch'; import path from 'path'; import { fileURLToPath } from 'url'; -import { generateFolderName,validateAndFixMarkdown } from './utils/utils.js'; +import { generateFolderName, validateAndFixMarkdown } from './utils/utils.js'; const isLagoon = !!process.env.LAGOON; const __filename = fileURLToPath(import.meta.url); @@ -13,7 +13,6 @@ const __dirname = isLagoon ? '/app/web/sites/default/files/converted' : path.dirname(__filename); - export async function fetchContentJinaAi(url) { const apiKey = process.env.JINA_AI_API_KEY || diff --git a/apps/converter/pdfToMarkdown.js b/apps/converter/pdfToMarkdown.js index fa50ca6e..0471c10d 100644 --- a/apps/converter/pdfToMarkdown.js +++ b/apps/converter/pdfToMarkdown.js @@ -3,7 +3,7 @@ import fs from 'fs-extra'; import path from 'path'; import { fileURLToPath } from 'url'; -import { generateFolderName,validateAndFixMarkdown } from './utils/utils.js'; +import { generateFolderName, validateAndFixMarkdown } from './utils/utils.js'; // @todo Fix this to work locally and live const isLagoon = !!process.env.LAGOON; @@ -12,7 +12,6 @@ const __dirname = isLagoon ? '/app/web/sites/default/files/converted' : path.dirname(__filename); - export async function pdfToMarkdown(pdfPath) { try { // Validate input file exists and is a PDF diff --git a/apps/converter/utils/utils.js b/apps/converter/utils/utils.js index 2f760632..e9d2dac8 100644 --- a/apps/converter/utils/utils.js +++ b/apps/converter/utils/utils.js @@ -50,38 +50,38 @@ export function generateFolderName(path) { } export function convertToMarkdown(input) { - const turndownService = new TurndownService({ - headingStyle: 'atx', - codeBlockStyle: 'fenced', - hr: '---', - bulletListMarker: '-', - strongDelimiter: '**', - }); + const turndownService = new TurndownService({ + headingStyle: 'atx', + codeBlockStyle: 'fenced', + hr: '---', + bulletListMarker: '-', + strongDelimiter: '**', + }); - turndownService.addRule('tables', { - filter: 'table', - replacement: function (content, node) { - const rows = node.querySelectorAll('tr'); - const headers = Array.from(rows[0]?.querySelectorAll('th,td') || []) - .map((cell) => cell.textContent.trim()) - .join(' | '); + turndownService.addRule('tables', { + filter: 'table', + replacement: function (content, node) { + const rows = node.querySelectorAll('tr'); + const headers = Array.from(rows[0]?.querySelectorAll('th,td') || []) + .map((cell) => cell.textContent.trim()) + .join(' | '); - const separator = headers - .split('|') - .map(() => '---') - .join(' | '); + const separator = headers + .split('|') + .map(() => '---') + .join(' | '); - const body = Array.from(rows) - .slice(1) - .map((row) => - Array.from(row.querySelectorAll('td')) - .map((cell) => cell.textContent.trim()) - .join(' | '), - ) - .join('\n'); + const body = Array.from(rows) + .slice(1) + .map((row) => + Array.from(row.querySelectorAll('td')) + .map((cell) => cell.textContent.trim()) + .join(' | '), + ) + .join('\n'); - return `\n${headers}\n${separator}\n${body}\n\n`; - }, - }); - return turndownService.turndown(input); + return `\n${headers}\n${separator}\n${body}\n\n`; + }, + }); + return turndownService.turndown(input); } diff --git a/packages/drupal/silverback_ai/modules/silverback_ai_import/silverback_ai_import.module b/packages/drupal/silverback_ai/modules/silverback_ai_import/silverback_ai_import.module index c2ca0024..7f145d96 100644 --- a/packages/drupal/silverback_ai/modules/silverback_ai_import/silverback_ai_import.module +++ b/packages/drupal/silverback_ai/modules/silverback_ai_import/silverback_ai_import.module @@ -50,7 +50,7 @@ function silverback_ai_import_form_node_page_split_form_alter(&$form, FormStateI '#title' => t('Drag and drop a Microsoft Word file'), '#type' => 'dropzonejs', '#required' => TRUE, - '#dropzone_description' => 'DropzoneJS description', + '#dropzone_description' => 'Drag and drop a file here', '#max_filesize' => '1M', '#max_files' => 1, '#extensions' => 'doc docx', diff --git a/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportAiService.php b/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportAiService.php index 423353f8..f4fc4484 100644 --- a/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportAiService.php +++ b/packages/drupal/silverback_ai/modules/silverback_ai_import/src/ContentImportAiService.php @@ -51,9 +51,9 @@ public function __construct( * The processed chunk after plugin conversion * * @throws \JsonException - * When JSON encoding/decoding fails + * When JSON encoding/decoding fails. * @throws \RuntimeException - * When no appropriate plugin is found for the chunk + * When no appropriate plugin is found for the chunk. * * @see getPlugin() * @see \Drupal\[module_name]\Plugin\ChunkConverterInterface::convert()