Skip to content

Commit

Permalink
fix(slb-495): eslint converter
Browse files Browse the repository at this point in the history
fix(slb-495): minor updates
  • Loading branch information
dspachos committed Dec 20, 2024
1 parent a707728 commit 9f23693
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 38 deletions.
6 changes: 5 additions & 1 deletion apps/converter/htmlToMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions apps/converter/jinaAi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ 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);
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 ||
Expand Down
3 changes: 1 addition & 2 deletions apps/converter/pdfToMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
60 changes: 30 additions & 30 deletions apps/converter/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9f23693

Please sign in to comment.