-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If there are semantic changes to be made by converting markdown, it suggests them. Part of #670.
- Loading branch information
Showing
4 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import snarkdown from 'snarkdown'; | ||
|
||
import { | ||
SuggestorArgs | ||
} from '../suggestions.js'; | ||
|
||
import { | ||
CardDiff, | ||
Suggestion | ||
} from '../types.js'; | ||
|
||
import { | ||
TEXT_FIELD_CONFIGURATION, | ||
editableFieldsForCardType | ||
} from '../card_fields.js'; | ||
|
||
import { | ||
cardDiffHasChanges | ||
} from '../card_diff.js'; | ||
|
||
import { | ||
TypedObject | ||
} from '../typed_object.js'; | ||
|
||
import { | ||
htmlIsEquivalent | ||
} from '../util.js'; | ||
|
||
//There can be missing concept links when concepts were added after a card was added. | ||
export const convertMarkdown = async (args: SuggestorArgs) : Promise<Suggestion[]> => { | ||
//TODO: isn't there a filter that does this? | ||
|
||
const {type, card, logger} = args; | ||
|
||
const diff : CardDiff = {}; | ||
|
||
for (const cardField of TypedObject.keys(editableFieldsForCardType(card.card_type))) { | ||
const config = TEXT_FIELD_CONFIGURATION[cardField]; | ||
if (!config.html) continue; | ||
const value = card[cardField] as string; | ||
const convertedValue = snarkdown(value); | ||
//The HTML might differ in whitespace. | ||
if (!htmlIsEquivalent(value, convertedValue)) { | ||
logger.info(`Suggesting converting for field ${cardField} ${value} to ${convertedValue}`); | ||
diff[cardField] = convertedValue; | ||
} | ||
|
||
} | ||
|
||
if (!cardDiffHasChanges(diff)) { | ||
logger.info('No changes proposed by markdown'); | ||
return []; | ||
} | ||
|
||
return [{ | ||
type, | ||
keyCards: [card.id], | ||
supportingCards: [], | ||
action: { | ||
keyCards: diff | ||
} | ||
}]; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters