venerdì 14 novembre 2014

I metadati di un testo

Livecode supporta l'inserimento di meta data all'interno di un testo, cioè l'inserimento di dati che non sono visibili all'utente che legge il testo.
Per inserire dei metatag ci sono vari modi: potete passare attraverso la proprietà htmlText:

set the htmlText of field 1 to "Testo normale. <span metadata=" & quote & "dato nascosto" & quote & ">Testo con metadata</span>"

come vedete è solo un tag span.
Oppure utilizzare la proprietà metadata:

set the metaData of word 3 to 5 of field 1 to "dato nascosto"


Cosa si può fare con i metadati? Esistono già le proprietà personalizzabili (cutom properties) che possono contenere dati non visibili all'utente, ma i metadati possono creare effetti legati al testo o trasferire informazioni che non debbono essere visualizzate dall'utente.
Come esempio pratico facciamo in modo che appaia il valore del metadato di una parola passandoci sopra il mouse:

on mouseMove
   if the mouseChunk is empty then
      exit mouseMove
   end if
   set the toolTip of me to the metaData of the mouseChunk
end mouseMove

Un altro modo per avere la lista dei metadati è passare attraverso l'array della proprietà StyledText; non che mi piaccia, ma può essere utile saperlo:

repeat for each element tParagraph in the styledText of field "Content"
   add 1 to theParagraphCount
   repeat for each element tRun in tParagraph["runs"]
      if tRun["metadata"] is not empty then
         put theParagraphCount & return & tRun["metadata"] & return & return after theOutput
      end if
   end repeat
end repeat
put theOutput


Nessun commento:

Posta un commento